-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.java
60 lines (60 loc) · 2.1 KB
/
calc.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.lang.Math;
import java.util.Scanner;
public class calc{
public static void main(String[] args){
System.out.println("Select operation");
int arth=0;
Scanner sc=new Scanner(System.in);
System.out.println("Select function:\n sum (1)\n subtraction (2)\n multiplication (3)\n division (4)\n ");
arth=sc.nextInt();
switch(arth){
case 1:
System.out.println("Sum");
int s=0,m=0;
System.out.println("enter two sumbers");
s=sc.nextInt();
m=sc.nextInt();
int s1=s+m;
System.out.println(s1);
break;
case 2:
System.out.println("subtraction");
int s5=0,m5=0;
System.out.println("enter two sumbers");
s5=sc.nextInt();
m5=sc.nextInt();
int s7=s5-m5;
System.out.println(s7);
break;
case 3:
System.out.println("multiplication");
int s4=0,m4=0;
System.out.println("enter two sumbers");
s4=sc.nextInt();
m4=sc.nextInt();
int s3=s4*m4;
System.out.println(s3);
break;
case 4:
System.out.println("division");
int s2=0,m2=0;
System.out.println("enter two sumbers");
s2=sc.nextInt();
m2=sc.nextInt();
if(m2==0){
System.out.println("cant divide by 0");
}
else if(s2<m2){
float r=(float)s2/(float)m2;
System.out.println(r);
}
else{
int s9=s2/m2;
System.out.println(s9);
}
break;
default:
System.out.println("Non valid");
}
}
}