Posts

Showing posts with the label switch case

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 ;...

Java program Vowels and Consonants splitter - switch case char

The java code splits a string into two string object containing vowels and consonants character.On executing the code, an input has a string and it is converted into array of char. and then each character is passed into switch case to check whether it is a vowel or consonant and stored into a string object separately. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SwitchCase { public static void main(String[] args) throws IOException { InputStreamReader dis = new InputStreamReader ( System.in ); BufferedReader br = new BufferedReader(dis); String tstr = "Enter a string sentence to split vowels and consonants" ; System.out.println(tstr); String arg1 =br.readLine(); char carr[]= arg1.toLowerCase().toCharArray(); StringBuffer vowels= new StringBuffer(); StringBuffer consnt= new StringBuffer(); ...

Java program Arithmetic calculator - switch case string

The javacode a simple arithmetic calculator using switch case with string constant . On executing the code, the used has to enter command and operands to do arithmetic operation. The command represented by string constant in switch-case specify which arithmetic operation is to do and The operands are integers on which the selected arithmetic operation is done.   for example of addition operation, a command add and followed by two integer.   "add 10 20".   for subtraction   "sub 10 20".  and for multiplication   "mul 10 20". import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SwitchCase { public static void main(String[] args) throws IOException { InputStreamReader dis = new InputStreamReader ( System.in ); BufferedReader br = new BufferedReader(dis); int ans=0; System.out.println( "Enter cmd & operand " ); String ...