Click to See Complete Forum and Search --> : String[] args Get Entered Number


The Little Guy
10-16-2007, 07:09 PM
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?

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

Khalid Ali
10-16-2007, 11:50 PM
Read up on using System.in