Skip to content

Commit 769bb63

Browse files
committed
Mini Calculate in Java
1 parent d2e4bf0 commit 769bb63

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Calculator.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.util.Scanner;
2+
3+
public class calculator
4+
{
5+
public static void main(String[] args)
6+
{
7+
float a, b, res;
8+
int choice;
9+
Scanner scan = new Scanner(System.in);
10+
11+
System.out.println("1. Addition");
12+
System.out.println("2. Subtraction");
13+
System.out.println("3. Multiplication");
14+
System.out.println("4. Division");
15+
System.out.print("Enter Your Choice (1-4): ");
16+
choice = scan.nextInt();
17+
18+
if(choice>=1 && choice<=4)
19+
{
20+
System.out.print("\nEnter any Two Number: ");
21+
a = scan.nextFloat();
22+
b = scan.nextFloat();
23+
24+
if(choice==1)
25+
res = a+b;
26+
else if(choice==2)
27+
res = a-b;
28+
else if(choice==3)
29+
res = a*b;
30+
else
31+
res = a/b;
32+
33+
System.out.println("\nResult = " +res);
34+
}
35+
else
36+
System.out.println("\nInvalid Choice!");
37+
}
38+
}

0 commit comments

Comments
 (0)