public  void readArguments(String[]args ) {
        String [] readArray = new String[ 10 ]; 
        Scanner readscanner=new Scanner(System.in); 
        // read values from keyboard into array 
        System.out.println("Enter your arguments or type Exit to exit the loop");
         for ( int i = 0 ; i <  readArray.length ; i ++) { 
                 if(readArray[i] =="Exit" ) break;                                    
                 readArray[i] = readscanner.nextLine();
   //Determine if the number of Arguments is less or greater than 5
               if(readArray.length<=4 ){
                  System.out.println("There are less than 5 arguments passed");
                 else {
                       System.out.println("More than 5 arguments passed");         

Edited by Ezzaral: Added code tags. Please use them to format all code that you post.

7 Years
Discussion Span
Last Post by hfx642

First, when you do "if(readArray =="Exit" ) break;", you don't actually check the value of the string, rather the position in the memory. To check the actual value, use readArray.equals("Exit").

Second, you need to place your if statement after your input. As it is now, at your if statement, readArray is null, since you haven't done anything with it yet. So your if-statement will never be true.

Votes + Comments
Very helpful answer to beginner question.

Another option would be to use a while loop.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.