-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_Calculator.java
More file actions
54 lines (47 loc) · 1.1 KB
/
Copy pathSimple_Calculator.java
File metadata and controls
54 lines (47 loc) · 1.1 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package practice;
import java.util.Scanner;
public class Simple_Calculator {
public static void main(String[] args) {
Simple_Calculator sv = new Simple_Calculator();
Scanner sc = new Scanner(System.in);
int arr [] = new int[5];
int i;
for(i =0; i<5;i++) {
System.out.println("Enter Number : ");
int number1 = sc.nextInt();
if(number1!=0) {
arr[i] = number1;// 5, 5, 4, 0
}
else {
break;
}
}
if(i==2) {
add(arr[0], arr[1]);
}
else if(i==3) {
add(arr[0], arr[1], arr[2]);
}
else if(i==4) {
add(arr[0], arr[1], arr[2], arr[3]);
}
else if (i==5) {
sv.add(arr[0], arr[1], arr[2], arr[3], arr[4]);
}
else {
System.out.println("Invalid!!! You must enter atleast two numbers");
}
}
static void add(int a, int b) {
System.out.println(a+b);
}
static void add(int a, int b, int c) {
System.out.println(a+b+c);
}
static void add(int a, int b, int c, int d) {
System.out.println(a+b+c+d);
}
void add(int a, int b, int c, int d, int e) {
System.out.println(a+b+c+d+e);
}
}