import java.util.*;
class Switch2
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
char ch;
int a,b,c;
System.out.println("\n\n\tInput Two Number.");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("\n\n\tCalculation Program.");
System.out.println("\n\n\tPress A for Addition + .");
System.out.println("\n\n\tPress S for Subtraction - .");
System.out.println("\n\n\tPress M for Multiplication * .");
System.out.println("\n\n\tPress D for Division / .");
System.out.print("\n\n\tMake Your Choice.===> ");
ch=sc.next().charAt(0); //There is No nextChar() in Java
switch(Character.toUpperCase(ch)) // Convert Lower case To Upper Case
{
case 'A': //case 'a':
System.out.println("\n\n\tAddition Program.");
c=a+b;
System.out.println("\n\n\tSum= ."+c);
break;
case 'S': //case 's':
System.out.println("\n\n\tSubtraction Program.");
c=a-b;
System.out.println("\n\n\tSubtraction= ."+c);
break;
case 'M': //case 'm':
System.out.println("\n\n\tMultiplication Program.");
c=a*b;
System.out.println("\n\n\tMultiplication= ."+c);
break;
case 'D': //case 'd':
System.out.println("\n\n\tDivision Program.");
c=a/b;
System.out.println("\n\n\tDivision= ."+c);
break;
default:
System.out.println("\n\tWrong Entry");
break;
}
}
}
No comments:
Post a Comment