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.
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());
}
}
Comments
Leave a comment