/*
 * @author BChepkwony
 * Created on 10 August 2011
 */
package com.jjpeople.mainmethod;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import java.util.Scanner;
import java.util.Arrays;

/**
 * MainMethodExercise demonstrates how you can pass in arguments into the
 * application.
 *
 * @author BChepkwony
 * Created on 10 August 2011
 */
public class MainMethodExercise {


    public Logger logger = Logger.getLogger( MainMethodExercise.class );

    


    /**
      *Read Arguments from run.bat file
      *@param args An Array of Args is passed
      */
     public  void readArguments(  readArray) {
         
        String[] readArray; 
        String [] readArray = new String[ 9 ]; 
        Scanner readscanner=new Scanner(System.in); 
         
        // read values from keyboard into array 
        System.out.println("Enter your arguments");
         for ( int i = 0 ; i <  readArray.length ; i ++) {
            
               
               System.out.println("The Arguments you entered is"+ ( i + 1 ));
               readArray[i] = readscanner.nextString();
               //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 if(readArray.length>=5){
                       System.out.println("More than 5 arguments passed");
                      
            
             }
               
              
              
             
                 
        
       } 
    }
     
    /**
     *Count in total the number of arguments read
     *Use log4j to Print the results on the console
     */
     

   //  public int countArguments( String args[] ) {
      
        //logger.debug( "In countArguments(..)" );


            // for(int i=0; i < readArray.length; i++){
                 //System.out.println("The number  of argments is:"+ readArray[i] ); 
             //}

           // for ( String argument : args ) {

               //System.out.println( "argument = " + argument );
            //}
        
   // }


    /**
     *  This is the starting execution point of the program.
     *
     * @param args the args are parameters passed into this java program from
     * the command line. In this example parameters are being passed into
     * this programme and the printed to the console.
     */
    public static void main( String[] args ) {
        
        MainMethodExercise mainMethodExercise=new MainMethodExercise();
        mainMethodExercise.readArguments(readArray);

        

       
    }
}

Please post a question. There is no question above.

Am trying to come up with a program that will allow me enter arguments from the keyboard, An store the arguments in an array of 10 elements, Also the program should print if the arguments entered is more than 5 or less and finally get the total number of arguments read from command line. thank you in advance.

That's your assignment, not a specific question. What are you having trouble with specifically? If you're receiving errors, post the stack traces.

error: cannot find symbol,
MainMethodExercise.readArguments(readArray);

You have not declared the readArguments() method correctly. Check the method signature and figure out what is missing.

You also do not have a "readArray" variable in main() at all. You can't pass an argument that doesn't exist.

I,ve modified the method signature to public static void readArguments( readArray), Am I suppose to declare the array also in the main method, Am not getting it please.

Hint: "One of these things is not like the others. One of these things does not belong. ..." :P

public void readArguments(  readArray) {
   	...

    public int countArguments( String args[] ) {
   	   	...

    public static void main( String[] args ) {
   	    ...

(...or really, one of them could be corrected. ;-)

thanks for that, i have changed the method signature to public void readArguments(String [] args), but now am getting an error: cannot find symbol mainMethodExercise.readArguments(readArray);
Symbol: variable readArray
Location: MainMethodExercise.
What have i not still not get right.

you have no readArray variable in your main method, but still you try to pass it as a parameter to your method.

Ezzaral already pointed this out.

also, realise there 's a difference between: reading input from the command prompt and command line parameters.

Now i have 1 error: cannot find symbol
readArray=readscannner.nextString() after declaring String [] readArray[9] in the main() method.

Finally i got what was wrong, i was using .nextString() method, instead of .nextLine() method. Now how can i exit the for loop prematurely.

/*
 * @author BChepkwony
 * Created on 10 August 2011
 */
package com.jjpeople.mainmethod;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import java.util.Scanner;
import java.util.Arrays;

/**
 * MainMethodExercise demonstrates how you can pass in arguments into the
 * application.
 *
 * @author BChepkwony
 * Created on 10 August 2011
 */
public class MainMethodExercise {


    public Logger logger = Logger.getLogger( MainMethodExercise.class );




    /**
      *Read Arguments from run.bat file
      *@param args An Array of Args is passed
      */
     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");
         for ( int i = 0 ; i <  readArray.length ; i ++) {


                 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");            





       } 
    }

    /**
     *Count in total the number of arguments read
     *Use log4j to Print the results on the console
     */


   //  public int countArguments( String args[] ) {

        //logger.debug( "In countArguments(..)" );


            // for(int i=0; i < readArray.length; i++){
                 //System.out.println("The number  of argments is:"+ readArray[i] ); 
             //}

           // for ( String argument : args ) {

               //System.out.println( "argument = " + argument );
            //}

   // }


    /**
     *  This is the starting execution point of the program.
     *
     * @param args the args are parameters passed into this java program from
     * the command line. In this example parameters are being passed into
     * this programme and the printed to the console.
     */
    public static void main( String[] args ) {
        String  [] readArray=new String [10];         
        MainMethodExercise mainMethodExercise=new MainMethodExercise();
        mainMethodExercise.readArguments(readArray);

        //BasicConfigurator.configure();

       // MainMethodExercise mainMethodExercisecounter = new MainMethodExercise();
       // mainMethodExercisecounter.countArguments( args );
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.