-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
52 lines (37 loc) · 778 Bytes
/
Calculator.java
File metadata and controls
52 lines (37 loc) · 778 Bytes
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
38
39
40
41
42
43
import java.util.Scanner;
class Calculator{
int num1;
int num2;
public void input(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number:");
num1=sc.nextInt();
System.out.println("Enter the second number:");
//Scanner sc2 = new Scanner(System.in);
num2=sc.nextInt();
}
public void add(){
int result=num1+num2;
System.out.println("Addition:"+result);
}
public void sub(){
int result=num1-num2;
System.out.println("Substraction:"+result);
}
public void mul(){
int result=num1*num2;
System.out.println("Multiplication:"+result);
}
public void div(){
int result=num1/num2;
System.out.println("Division:"+result);
}
public static void main(String[] args){
Calculator a = new Calculator();
a.input();
a.add();
a.sub();
a.mul();
a.div();
}
}