Write a program java make calculator (Addition, Subtraction, Multiplication and Division). - Pratik Ghelani

Pratik Ghelani

Breaking

Friday, January 25, 2019

Write a program java make calculator (Addition, Subtraction, Multiplication and Division).

Program:-

import java.util.Scanner;
public class p4b {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, c, d;
System.out.print("Enter the numbers: ");
a = sc.nextInt();
System.out.print("Enter the numbers: ");

b = sc.nextInt();
Programming With Java
System.out.println("1. Add(+): ");
System.out.println("2. SUB(-): ");
System.out.println("3. MUL(*): ");
System.out.println("4. DIV(/): ");
System.out.print("Enter the choice :- \t");
c = sc.nextInt();
switch (c) {
case 1:
d = a + b;
System.out.println("add:-\t " + d);
break;
case 2:
d = a - b;
System.out.println("Sub:- \t" + d);
break;
case 3:
d = a * b;
System.out.println("mul:- \t" + d);
break;
case 4:
d = a / b;
System.out.println("Div: - \t" + d);
break;
default:
System.out.println("Wrong input:-");
}
}

}

Output:-






No comments:

Post a Comment