Answer to Question #244713 in Java | JSP | JSF for Jay

Question #244713

For you to explore Java String Methods, you need to create a Java program that will

perform the following:

1. Count the number of characters in a string input;

2. Change the orientation of the characters from lowercase to uppercase and vice

versa;

3. Change every occurrence of charToBe replaced is replaced with

charReplacedWith;

4. Display the reverse of the entire string input.


1
Expert's answer
2021-10-01T01:30:45-0400


package methodsstring;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class MethodsString {


    
    public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter a string\n");
       String s = scan.next();
        System.out.printf("%s has %d characters\n", s, s.length());
        String upper = s.toUpperCase();
         System.out.printf("%s to upper case is %s \n", s, upper);
        String lowe = s.toLowerCase();
        System.out.printf("%s to lower case is %s \n", s, lowe);
         StringBuilder input1 = new StringBuilder();
        String re =  s.replace('a', 'c');
        System.out.printf("%s after replacing character a to c\n", re);
         input1.append(s);
         System.out.print(input1.reverse());
         
       
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS