www.webdeveloper.com
Results 1 to 2 of 2

Thread: String[] args Get Entered Number

  1. #1
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287

    String[] args Get Entered Number

    OK, I ask how many students there are, and the user enters a number, then this will loop through the number of times that the user entered.

    using String[] args, how do I get what was entered in the CMD window?

    Code:
    public class hw4{
    	public static void main(String[] args){
    		int numStu = 15;
    		if(args.length != 1){
    			System.out.println("Tell me how many students");
    			System.exit(0);
    		}else{
    			numStu = Integer.parseInt(args[0]);
    		}
    		Person p = new Person("perry",1990);
    		Employee e = new Employee ("perry",1990,52321);
    		Student[] s = new Student[numStu];
    		for(int i=0;i < s.length;i++){
    			int x = 1 + (int)(Math.random()*4);
    			int y = 10000 + (int)(Math.random()*99999);
    			s[i] = new Student("Name"+i,(int)(Math.random()*10000)%20+1970,"CCIS",y,x);
    			System.out.println(s[i].toString());
    		}
    		/*for(int j=0;j < t.length;j++){
    			int x = 1 + (int)(Math.random()*4);
    			int y = 10000 + (int)(Math.random()*99999);
    			int z = 1000 + (int)(Math.random()*80000);
    			s[j] = new Employee("Name"+j,(int)(Math.random()*10000)%20+1970,z,y,x);
    			System.out.println(s[j].toString());
    		}
    		*/
    		System.out.println(e);
    	}
    }
    My settings

    Browser :: FireFox 1.5
    Resolution :: 1152x864
    Connection :: Cable Modem 2Mbs

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    Read up on using System.in
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles