Skip to content

Commit 11cf1cb

Browse files
authored
Create CommandlineArguments.java
1 parent 3a24add commit 11cf1cb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class CommandlineArguments{
2+
/**
3+
* Returns the sum of n number of command line arguments(Double datatype)
4+
* To execute run java CommandlineArguments 12.0 3.0 (Example)
5+
*/
6+
7+
public static void main(String s[])
8+
{
9+
double sum=0;
10+
/**
11+
* try-catch block to check for runtime input errors
12+
*
13+
*/
14+
15+
try{
16+
17+
for(int i =0 ;i<s.length;i++)
18+
{
19+
sum =sum+Double.parseDouble(s[i]);
20+
}
21+
22+
System.out.print("\n Sum is " + sum);
23+
24+
}
25+
catch(Exception e){
26+
System.out.print("\n please check input");
27+
}
28+
29+
}
30+
}

0 commit comments

Comments
 (0)