-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddition_of_numbers.java
More file actions
53 lines (48 loc) · 1.12 KB
/
addition_of_numbers.java
File metadata and controls
53 lines (48 loc) · 1.12 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
/*
Input -> 3
3 4 5
Output -> 12
*/
import java.util.Scanner;
class Main{
int sum(int a,int b)
{
return a+b;
}
int sum(int a,int b,int c)
{
return a+b+c;
}
int sum(int a,int b,int c,int d)
{
return a+b+c+d;
}
public static void main(String[] args)
{
int n,a,b,c,d;
Main o1=new Main();
Scanner s=new Scanner(System.in);
n = Integer.parseInt(s.nextLine());
if(n==2)
{
a=Integer.parseInt(s.nextLine());
b=Integer.parseInt(s.nextLine());
System.out.println(o1.sum(a,b));
}
else if(n==3)
{
a=Integer.parseInt(s.nextLine());
b=Integer.parseInt(s.nextLine());
c=Integer.parseInt(s.nextLine());
System.out.println(o1.sum(a,b,c));
}
else
{
a=Integer.parseInt(s.nextLine());
b=Integer.parseInt(s.nextLine());
c=Integer.parseInt(s.nextLine());
d=Integer.parseInt(s.nextLine());
System.out.println(o1.sum(a,b,c,d));
}
}
}