-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
37 lines (36 loc) · 1.41 KB
/
Calculator.java
File metadata and controls
37 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class Calculator{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
boolean running = true;
while(running){
System.out.println("Bienvenue dans votre calculatrice :");
System.out.println("Addition : 1");
System.out.println("Soustraction : 2");
System.out.println("Multiply : 3");
System.out.println("Divide : 4");
System.out.println("Exit : 5");
System.out.println(" Choose an operation : ");
int choice = scan.nextInt();
if(choice == 5){
running = false;
System.out.println("Goodbye!");
break;
}
System.out.println("Enter the first number a : ");
double a = scan.nextDouble();
System.out.println("Enter the second number b : ");
double b = scan.nextDouble();
double result = 0;
switch(choice){
case 1 : result = Operations.add(a,b); break;
case 2 : result = Operations.subtract(a,b); break;
case 3 : result = Operations.multiply(a,b); break;
case 4 : result = Operations.divide(a,b); break;
default : System.out.println("Invalide choice !"); break;
}
System.out.println("Result : "+ result);
}
scan.close();
}
}