SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.Scanner; | |
| 2 | ||
| 3 | public class Calculator | |
| 4 | {
| |
| 5 | public static void main(String[] args) | |
| 6 | {
| |
| 7 | Scanner scan=new Scanner(System.in); | |
| 8 | int a,b; | |
| 9 | System.out.println("Enter Two Integer Number");
| |
| 10 | a=scan.nextInt(); | |
| 11 | b=scan.nextInt(); | |
| 12 | System.out.println("Enter '+' or '-' or '*' or '/' which you want: ");
| |
| 13 | char ch=scan.next().charAt(0); | |
| 14 | switch (ch) | |
| 15 | {
| |
| 16 | case '+': | |
| 17 | System.out.println("Sum of "+a+ " + "+b+" = "+(a+b));
| |
| 18 | break; | |
| 19 | case '-': | |
| 20 | System.out.println("Sub of "+a+ " - "+b+" = "+(a-b));
| |
| 21 | break; | |
| 22 | case '*': | |
| 23 | System.out.println("Mul of "+a+ " X "+b+" = "+(a*b));
| |
| 24 | break; | |
| 25 | case '/': | |
| 26 | System.out.println("Div of "+a+ " / "+b+" = "+(a/b));
| |
| 27 | break; | |
| 28 | default: | |
| 29 | System.out.println(" Wrong Input\n");
| |
| 30 | break; | |
| 31 | } | |
| 32 | } | |
| 33 | } | |
| 34 | /* | |
| 35 | public class Calculator | |
| 36 | {
| |
| 37 | static Scanner scan=new Scanner(System.in); | |
| 38 | public static void main(String[] args) | |
| 39 | {
| |
| 40 | int a,b; | |
| 41 | prln("Enter Two Integer Number:");
| |
| 42 | a=scan.nextInt(); | |
| 43 | b=scan.nextInt(); | |
| 44 | pr("Enter + 0r - or * 0r / which You want: ");
| |
| 45 | char ch=scan.next().charAt(0); | |
| 46 | switch (ch) {
| |
| 47 | case '+': prln("Sum of "+a+ " + "+b+" = "+(a+b));
| |
| 48 | break; | |
| 49 | case '-': prln("Sub of "+a+ " - "+b+" = "+(a-b));
| |
| 50 | break; | |
| 51 | case '*': prln("Mul of "+a+ " X "+b+" = "+(a*b));
| |
| 52 | break; | |
| 53 | case '/': prln("Div of "+a+ " / "+b+" = "+(a/b));
| |
| 54 | break; | |
| 55 | default:prln(" Wrong Input\n");
| |
| 56 | break; | |
| 57 | } | |
| 58 | } | |
| 59 | static void prln(Object any) | |
| 60 | {
| |
| 61 | System.out.println(any); | |
| 62 | } | |
| 63 | ||
| 64 | static void pr(Object any) | |
| 65 | {
| |
| 66 | System.out.print(any); | |
| 67 | } | |
| 68 | } | |
| 69 | */ |