By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,891 Members | 813 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,891 IT Pros & Developers. It's quick & easy.

sum in command line argument

P: 1
Expand|Select|Wrap|Line Numbers
  1. class N2
  2. {
  3.   public static void main(String[] args){
  4.  
  5.       int a,b,c;
  6.  
  7.       int  sum=0;
  8.  
  9.       for(int i=0;i<=args.length;i++)
  10.       {      
  11.           {
  12.  
  13.               sum+=i;
  14.  
  15.           }
  16.  
  17.           System.out.println(sum);
  18.      }
  19.  
  20. }
  21. }
Nov 29 '19 #1
Share this Question
Share on Google+
3 Replies

gits
Expert Mod 5K+
P: 5,390
do you have a question regarding the code you posted?
Nov 29 '19 #2

P: 33
First of all, You have to post the question regarding the code
But as per your code, I think you want to sum the a,b, and c variable in which value comes from the command line argument
So you should run the code by the following command in which the parameters are passed at run time

javac N2.java
java N2 4 5 6
2 Weeks Ago #3

dev7060
Expert 100+
P: 311
First, OP didn't even use the declared vars. Second, the program won't work unless the values are parsed as int. Third, the output statement to print the sum is in the wrong block.
2 Weeks Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.