-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalaculates.java
More file actions
32 lines (25 loc) · 1.04 KB
/
Calaculates.java
File metadata and controls
32 lines (25 loc) · 1.04 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
import java.util.Scanner;
public class Calaculates {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter 'a' to add, 's' to subtract, 'm' to multiply, 'd' to divide ");
String operation = scan.next();
System.out.println("Enter the 1st number: ");
int firstNumber = scan.nextInt();
System.out.println("Enter the second number: ");
int secondNumber = scan.nextInt();
operateTwonumbers( operation, firstNumber, secondNumber);
}
public static void operateTwonumbers(String operation, int firstNumber, int secondNumber){
System.out.print("The answer is: ");
if(operation.charAt(0)=='a'){
System.out.println( firstNumber + secondNumber);
}else if(operation.charAt(0)=='s'){
System.out.println( firstNumber - secondNumber);
}else if(operation.charAt(0)=='m'){
System.out.println( firstNumber*secondNumber);
}else if(operation.charAt(0)=='d'){
System.out.println( firstNumber/secondNumber);
}
}
}