-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcse310_week6_day2_ques1.java
65 lines (62 loc) · 1.46 KB
/
cse310_week6_day2_ques1.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
61
62
63
64
65
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int x=sc.nextInt();
if(x>0)
{
int []ar=new int[x];
for(int i=0;i<x;i++)
{
ar[i]=sc.nextInt();
}
int n=sc.nextInt();
switch(n)
{
case 1:
Integer o=new Integer();
o.add(ar);
break;
case 2:
Integer o1=new Integer();
o1.mul(ar);
break;
default:
System.out.println("Wrong Choice");
System.exit(0);
}
}
else
{
System.out.println("Invalid Array Size");
System.exit(0);
}
}
}
class Integer
{
static void add(int ar[])
{
int n=ar.length;
int sum=0;
for(int i=0;i<n;i++)
{
sum+=ar[i];
}
System.out.println(sum);
}
static void mul(int ar[])
{
int n=ar.length;
int sum=1;
for(int i=0;i<n;i++)
{
sum*=ar[i];
}
System.out.println(sum);
}
}