Skip to content

Instantly share code, notes, and snippets.

@ruddha2001
Created July 7, 2020 20:40
Show Gist options
  • Save ruddha2001/5af60b87c3bf2979e2d500a04da67cde to your computer and use it in GitHub Desktop.
Save ruddha2001/5af60b87c3bf2979e2d500a04da67cde to your computer and use it in GitHub Desktop.
/**
* SumOfNumbers - To find the sum of all the numbers passed as command line
* input
*/
public class SumOfNumbers {
public static void main(String[] args) {
int len = args.length; // Length of the array args
int sum = 0; // Variable to hold our result
for (int i = 0; i < len; i++)
sum += Integer.parseInt(args[i]); // Parsing each string item to Integer and add to sum
System.out.print(sum); // Printing the result to standard console
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment