954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to count arguments in for loop entered from the keyboard

public int countArguments( String args[] ) {

        logger.debug( "In countArguments(..)" );
                     
            String [] readArray= new String [10];
            for ( int i=0; i<readArray.length;  i++ ) {
                for(int count: readArray){ 
                 count=count+i;
                System.out.println( "Number of arguments = " + count );
                }
            }
        
    }
betny
Newbie Poster
20 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

No need for such looops
args.length use this to display how many arguments were entered...

Vaspar
Light Poster
28 posts since Feb 2011
Reputation Points: 19
Solved Threads: 1
 

Thanks alot it is working now....

public void countArguments( String args[] ) {

        logger.debug( "In countArguments(..)" );
                     
        if ( args.length == 0 ) {

            System.out.println(
                    "No arguments were passed to this application" );
        }
        else {           

                System.out.println( "The number of arguments passed = " + args.length );
            
        }
            
    }
betny
Newbie Poster
20 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Mark thread as solved...

Vaspar
Light Poster
28 posts since Feb 2011
Reputation Points: 19
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: