Home Answers Viewqa Java-Beginners STRING FUNCTIONS

 
 


alfred augustin
STRING FUNCTIONS
2 Answer(s)      2 years and 6 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.

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 Pages:
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
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
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
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
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
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
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
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
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
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
javascript array functions push
javascript array functions push var array = new Array...--; } } function show() { var string="All...++) { string =string+array[i
jQuery Utility Functions
jQuery Utility Functions      In this section we are discussing about jQuery Utility Functions. Understanding these functions are important as you will have to use
PHP Variables Functions
PHP Variables Functions In this tutorial we learned about how to create functions or how to use predefined functions. If you want to see the real power of PHP you should use PHP functions. There are more than 700 in-built functions
Hibernate Aggregate Functions
Hibernate Aggregate Functions In this tutorial you will learn about aggregate functions in Hibernate In an aggregate functions values of columns... supports various useful Aggregate functions some of these are : avg(...), avg
php Variables and Functions
PHP Variables Functions( ) In this chapter we will learn about PHP functions( ). Most of the beginners always think, why we create functions and  how does it help to the program? We create functions to make the program easier
JavaScript User Defined Functions
JavaScript User-Defined Functions: An user-defined function saves  us... them to work. JavaScript has so many built-in functions, besides  that you... 3 (Return a String): <html> <head> <title>Write your
array string
array string  how to sort strings with out using any functions
greatest of 3 numbers using classes and functions.
greatest of 3 numbers using classes and functions.  WAP to calculate greatest of 3 numbers using classes and functions with parameters through input... FindLargest{ public static void main(String[] args){ int max = Integer.MIN
jsp- adding user defined functions to a jsp
jsp- adding user defined functions to a jsp  Trying to write... and how to correct it. <% public String retrieveAndClearErrorMessage(HttpSession session) { String errorMessage = (String
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
JavaScript array of functions
JavaScript array of functions   ... in understanding a JavaScript array of functions. For this we are using Java Script... a variable hold the string. The for loop execute and run the script till variable i
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
JSTL Functions
JSTL Functions syntax : <%@ taglib prefix = "fn"... named var. We are going to use the various functions provided to us by the jstl functions library.  The JSTL functions library has many methods. We
Hibernate Avg() Function (Aggregate Functions)
Hibernate Avg() Function (Aggregate Functions)  ... to use the avg() function. Hibernate supports multiple aggregate functions. When...;public static void main(String[] args) {   // 
Hibernate Max() Function (Aggregate Functions)
Hibernate Max() Function (Aggregate Functions... to use the Max() function. Hibernate supports multiple aggregate functions. When...;mail_mevinod@yahoo.co.in  */   public static void main(String
Hibernate Min() Function (Aggregate Functions)
Hibernate Min() Function (Aggregate Functions)  ... the Min() function. Hibernate supports multiple aggregate functions. When...  */   public static void main(String[] args
string validation in php - PHP
string validation in php  Can you please post a example of PHP Built-in String Validation Functions
Stored Procedures and Functions
Stored Procedures and Functions       Stored Routines (Procedures and Functions) are supported... ...] characteristic: SQL SECURITY {DEFINER | INVOKER}| COMMENT 'string' Example
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
SQL Functions
SQL Functions      ... the string, with sub string beginning at position pos and len.This is a synonym for SUB STRING( str , pos , len ) .   Mysql Merge
Inbuild functions
Inbuild functions  List all the inbuild functions in java
Operators & Functions
Operators & Functions     ...; In this section we will describes the functions, which can be used to manipulate... specifiers may be used in the format string. The ?%? character is required before
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
String Array - Java Beginners
String Array  From where can I get, all the functions that are needed for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String
how do i apply the javascript validation functions to the iframe content?
how do i apply the javascript validation functions to the iframe content?  Hi friends am Yogesh Nandane..Developing a small accessibility evaluation... for most things and convert back to a string // here using
how do i apply the javascript validation functions to the iframe content?
how do i apply the javascript validation functions to the iframe content?  Hi friends am Yogesh Nandane..Developing a small accessibility evaluation... for most things and convert back to a string // here using
String Array - Java Beginners
String Array  From where can I get, all the functions that are needed for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String
PHP Array to String Conversion
PHP Array to String Conversion Sometimes data arrive in array which has to be convert into string, in this situation we can use implode() function which is used to convert the array into string. In PHP, conversion of an array to string
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
Boolean functions in JavaScript
Boolean functions in JavaScript  Explain about the Boolean functions present in Javascript
What are encryption functions in PHP?
What are encryption functions in PHP?  What are encryption functions in PHP
decodeURI() and encodeURI() functions in JavaScript
decodeURI() and encodeURI() functions in JavaScript  What are decodeURI() and encodeURI() functions in JavaScript
functions strstr() and stristr().
functions strstr() and stristr().  What is the functionality of the functions strstr() and stristr
the functions unlink and unset
the functions unlink and unset  What is the difference between the functions unlink and unset
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.