mathajax

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
Output2
String functions menu

0- Reverse 
1- UpperCase  
2- LowerCase 
3- Length 

Enter string
hello
Enter course choice
1
ans :HELLO




Comments

Popular posts from this blog

Matrix Forward and Back Substitution

Solving System of Linear Equations by Gauss Jordan Elimination

Distance Metric - Euclidean Distance

Solve System of Linear Equations by LU Decompose

Matrix in Java