Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm adding a calculator program using Java #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions DO_A1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.util.Scanner;

public class DO_A1 {

int add(int a, int b) {
return a + b;
}

int sub(int a, int b) {
return a - b;
}

int mult(int a, int b) {
return a * b;
}

float div(int a, int b) {
return a / b;
}

public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int a, b, ad, s, m, ch;
a = sc.nextInt();
b = sc.nextInt();
float d;
System.out
.println("Enter choice as 1 for sum, 2 for subtraction, 3 for multiplication and 4 for division:");
ch = sc.nextInt();
Calculator c = new Calculator();
if (ch == 1) {
ad = c.add(a, b);
System.out.println(ad);
} else if (ch == 2) {
s = c.sub(a, b);
System.out.println(s);
} else if (ch == 3) {
m = c.mult(a, b);
System.out.println(m);
} else if (ch == 4) {
d = c.div(a, b);
System.out.println(d);
}
}
}
}