Java program String object member function access - switch case int
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SwitchCase3
{
public static void main(String[] args) throws IOException
{
InputStreamReader dis =new InputStreamReader ( System.in );
BufferedReader br =new BufferedReader(dis);
System.out.println("String functions menun");
String menustr="0- Reverse 1- UpperCase 2- LowerCase
3- Length ";
System.out.println(menustr);
System.out.println("nEnter string");
String inpstr =br.readLine();
System.out.println("Enter course choice");
String choice =br.readLine();
int cs = Integer.parseInt(choice);
switch( cs )
{
case 0:
StringBuffer sbuf=new StringBuffer(inpstr);
String rev =sbuf.reverse().toString();
System.out.println("ans :"+ rev);
break;
case 1:
String ucstr =inpstr.toUpperCase();
System.out.println("ans :"+ ucstr);
break;
case 2:
String lcstr =inpstr.toLowerCase();
System.out.println("ans :"+ lcstr);
break;
case 3:
int len =inpstr.length();
System.out.println("ans :"+ len);
break;
default :
System.out.println("case:"+ cs +" not support ");
}
}
}
Output
String functions menu 0- Reverse 1- UpperCase 2- LowerCase 3- Length Enter string hello Enter choice 0 ans :olleh
String functions menu 0- Reverse 1- UpperCase 2- LowerCase 3- Length Enter string hello Enter course choice 1 ans :HELLO
Related Post
Arithmetic Operation - Switch case constant string
Vowels and Consonants splitter - switch case with conditional char
String object member function access - switch case with condition constant integer
Arithmetic Operation - Switch case constant string
Vowels and Consonants splitter - switch case with conditional char
String object member function access - switch case with condition constant integer
Comments
Post a Comment