-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Switch Case statement
More file actions
42 lines (36 loc) · 1.18 KB
/
Java Switch Case statement
File metadata and controls
42 lines (36 loc) · 1.18 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
//{ Driver Code Starts
// Initial Template for Java
import java.io.*;
import java.util.*;
class GFG{
public static void main(String args[])throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(in.readLine());
while(t-- > 0){
int choice = Integer.parseInt(in.readLine());
String a[] = in.readLine().trim().split("\\s+");
List<Double> arr = new ArrayList<Double>();
for(int i = 0;i < choice;i++)
arr.add(Double.parseDouble(a[i]));
Solution ob = new Solution();
if(choice == 1)
System.out.println(String.format("%.2f", ob.switchCase(choice, arr)));
else
System.out.println((int)ob.switchCase(choice, arr));
}
}
}
// } Driver Code Ends
// User function Template for Java
class Solution{
static double switchCase(int choice, List<Double> arr){
// code here
if(choice==1){
return Math.PI*Math.pow(arr.get(0),2);}
else if(choice==2){
return arr.get(0)*arr.get(1);
}
return 0;
}
}