write a program in bluej to input a string and convert it to upper case
Answers
Explanation:
String.toLowerCase()
It is predefined (built-in) method of String class in Java, it returns lowercase string.
String.toUpperCase()
It is predefined (built-in) method of String class in Java, it returns uppercase string.
Consider the program:
This an example of Java string programs, In this program a string is given in any case and we have to convert it into uppercase and lowercase.
Copy
/*Java program to convert string into Lowercase and Uppercase*/
import java.util.*;
class ConvertCasePrg
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
String str="";
//input string
System.out.print("Enter any string: ");
str=sc.nextLine();
//declaring objects to store lowercase and uppercase strings
String lowerCaseString="",upperCaseString="";
//convert into lower case
lowerCaseString= str.toLowerCase();
//convert into upper case
upperCaseString= str.toUpperCase();
//printing the strings
System.out.println("Original String: "+str);
System.out.println("Lower Case String: "+lowerCaseString);
System.out.println("Upper Case String: "+upperCaseString);
}
}
Answer:
hi hru dear
Explanation:
....................................