switch case
import java.util.Scanner; class P11SwitchCase { public static void main() { int x,y; System.out.println("Enter two integer"); Scanner in = new Scanner(System.in); x = in.nextInt(); y = in.nextInt(); System.out.println("Enter the operation you want to perform \n + for addition "); System.out.println(" - for subtraction \n * for multiplication \n / for division\n\n"); char c = in.next().charAt(0); while(c!= '+' && c!= '-' && c!= '*' && c!= '/' ) { System.out.println("Enter proper symbol"); c = in.next().charAt(0); } switch(c) { case '+': System.out.println("Required result = "+(x+y)); break; case '-': System.out.println("Required result = "+(x-y)); break; case '*': System.out.println("Required result = "+(x*y)); break; case '/': System.out.println("Required result = "+(x/y)); break; } } }
Comments
Post a Comment