Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners STRING FUNCTIONS

Have Programming Question? Ask it here!
 
 
 


alfred augustin
STRING FUNCTIONS
2 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


HERE IS THE QUESTION THAT I HAVE IN MY INFORMATICS PRACTICES CLASS XII TEXTBOOK ---

Qn. Design an application that accepts a string and 2 integers from user. It then changes the case of characters at those indices as specified by 2 integers entered by the user.

--- if you do have an answer for this please post it as soon.

Thank you.


Advertisement
View Answers

November 22, 2010 at 3:26 PM


Hi Friend,

Try the following code:

import java.util.*;
class  StringExample{
    public static String removeCharAt(String s, int pos) {
   StringBuffer buf = new StringBuffer( s.length() - 1 );
   buf.append( s.substring(0,pos) ).append( s.substring(pos+1) );
   return buf.toString();
}

    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        System.out.print("Enter String: ");
        String st=input.nextLine();
        System.out.print("Enter first integer: ");
        int index1=input.nextInt();
        System.out.print("Enter second integer: ");
        int index2=input.nextInt();
        String st1=st.substring(index1,index1+1);
        String st2=st.substring(index2,index2+1);
        String str1=removeCharAt(st,index1);
        String str=new StringBuffer(str1).insert(index1, " ").toString();
        String str2=removeCharAt(str,index2);
        String newString=removeCharAt(str2,index1);
        String st3="",st4="";
        char ch1=st1.charAt(0);
        char ch2=st2.charAt(0);
        if(Character.isLowerCase(ch1)){
         st3=st1.toUpperCase();
        }
        else if(Character.isUpperCase(ch1)){
         st3=st1.toLowerCase();
        }
        if(Character.isLowerCase(ch2)){
         st4=st2.toUpperCase();
        }
        else if(Character.isUpperCase(ch2)){
         st4=st2.toUpperCase();
        }
       StringBuffer buffer=new StringBuffer(newString);
       buffer.insert(index1,st3).insert(index2,st4);
       System.out.println(buffer.toString());
    }
}

Thanks



November 22, 2010 at 10:32 PM


THAK YOU VERY MUCH !!! GOD BLESS YOU !!! I will be trying this code now and see if it is correct or not ok ?...

Thank you.



Related Tutorials/Questions & Answers:
STRING FUNCTIONS
STRING FUNCTIONS  HERE IS THE QUESTION THAT I HAVE IN MY INFORMATICS... a string and 2 integers from user. It then changes the case of characters at those... String removeCharAt(String s, int pos) { StringBuffer buf = new StringBuffer
Program using String functions - Java Beginners
Program using String functions  Write a program to accept a sentence... { public static void main(String[] args) { int count = 0...); System.out.print("Enter string:"); String st = input.nextLine
Advertisements
Input - Output String Functions
Input - Output String Functions       This tutorial is showing some functions that you need to use for your taking... a string data and input them directly into your database. Some special characters
Java reverse string without using inbuilt functions
Java reverse string without using inbuilt functions In this tutorial, you will learn how to reverse string without using any inbuilt functions. Here, we have created a method to reverse the string and returns a new string with reverse
String Functions In Java
String Functions In Java In this section we will see various methods of String... in a simple example. String class is belongs to the java.lang package. It is a final class i.e. it can not be extended. Because the String class is defined
What is functions?
What is functions?  Hi, Please tell me about PHP functions? Thanks in advance
What is functions?
What is functions?  Hi, Please tell me about PHP functions? Thanks in advance
What is functions?
What is functions?  Hi, Please tell me about PHP functions? Thanks in advance.   About Functions: Functions in PHP is block of code... functions and use it multiple times. In PHP there is many pre-defined functions
Inbuild functions
Inbuild functions  List all the inbuild functions in java
String
String  how to add spaces with string functions.?   Hi... String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n) { return
Functions and Methods
Functions and Methods  Write a Java program to input the sides... { public static void decide(int side1,int side2,int side3){ String..."; System.out.println(type); } public static void main(String[] args
MySQL String Function
; In this section you can learn about the uses of MySQL String functions. These functions can be used to manipulate the string data. Here we have compiled the almost all String functions that you can use to learn more about string
Functions and Methods
Functions and Methods  (1) Write a program in java to input 10... a string. Pass it to a function freq(String x),the function finds and prints the frequency of each vowel. (5) Write a program in Java to input a string using
static functions
2. Static Functions 3. Instance Variable  Static Variables Static... main(string args[]){ a obj=new a();//can ,t requirement of it a.display...{ public static void main(string args[]){ a obj=new a();//can ,t requirement
JavaScript String Function
JavaScript String Function Almost every language provides special attention towards string and string manipulation, JavaScript is no exception. It provides many built-in functions to manipulate a string.  Java String Function
without using built-in functions
without using built-in functions  Hai sir... Please help me to solve this... Findout occurances of each string in every another string (built - in functions are not at all allowed) all, and, sand, falling wall and sand
PHP Functions, PHP Functions Tutorials
PHP Functions In this section we will understand important PHP functions with the help of example code. What is Functions? Function is a block of code...; } Functions in PHP PHP provides many built-in functions to do the real job
the functions unlink and unset
the functions unlink and unset  What is the difference between the functions unlink and unset
functions strstr() and stristr().
functions strstr() and stristr().  What is the functionality of the functions strstr() and stristr
decodeURI() and encodeURI() functions in JavaScript
decodeURI() and encodeURI() functions in JavaScript  What are decodeURI() and encodeURI() functions in JavaScript
What are encryption functions in PHP?
What are encryption functions in PHP?  What are encryption functions in PHP
Boolean functions in JavaScript
Boolean functions in JavaScript  Explain about the Boolean functions present in Javascript
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array
string
string  String helloString = new String(helloArray); System.out.println(helloString); i am unable to understand this. could u plz explain
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
string
ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String: "); String st=input.nextLine(); String str[]=st.split(" "); for(int i=0
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
String
String  how to print in between numbers if the question "String s = "1,2,3,4,5,6,8,-25"" out must be 1 2,3,4,5,6,7,8,9,10,upto25
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  write a program to accept the string and store the reverse stream into another array and print
string
and also displaying that contain word? Like I want to find "a" in the string... and a character. It then count the occurrence of that character in the string and display... String_Example { public static void main(String[] args
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
string
string  a java program using string function that computes your initials from your full name and display them   Please visit the following links: http://www.roseindia.net/tutorial/java/core/printInitials.html http
string
string  a java program using string function and access modifiers to automate the insurance company which will have to manage the information about policy holders Data Members: 1)Policy No 2)Name of policy holder 3)Address 4
Even and odd functions in java
Even and odd functions in java  Even and odd functions in java  ... static void main(String[] args) { Scanner input = new Scanner(System.in... have two separate functions for checking either number is even or odd. We
Boolean functions present in Javascript
Boolean functions present in Javascript   Explain about the Boolean functions present in Javascript
php array functions
php array functions  php array functions list
JavaScript Variadic functions
JavaScript Variadic functions  Explain about Variadic functions
php stream functions
php stream functions  what does php stream functions do
Inverse of trigonometric functions in java.
Inverse of trigonometric functions in java.  How to get inverse of trigonometric functions in java?   public class InverseTrigno { public static void main(String[] args) { double degrees = 30; double
What is Character Functions
What is Character Functions  What is Character Functions   Hi, Here is the answer, Character Functions are INITCAP, UPPER, LOWER, SUBSTR & LENGTH. Additional functions are GREATEST & LEAST. Group Functions
c-language pointer functions
c-language pointer functions  what is the execution process of character pointer functions with example
Confusion on Functions. Help Please?!
Confusion on Functions. Help Please?!  Write a program which has a number of functions for getting the area i.e. area of circle, area of square, area of rectangle and area of cylinder. Right, I've got some of it, but I'm just
 

 

 

DMCA.com