Reading from a command line to an array argument (Java)
Posted on 2006-05-10
Platform = Windows XP
Java version = >1.5
I'm trying to make an alternate version of my Football Fantasy program. In this second version, I want to be able to get names of players via a command line, and create an array of rosters. So I guess each player's name would create an element in the array for a roster. Can someone help me with how to assign the member field with the name of the player read in from the command line?
Here is what my code looks like now for the driver program:
// Import Java package
// Class name
public class FootballScores
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
public static void main(String args) throws IOException
// Create an array of rosters & get input from an array argument (not keyboard)
Roster arrayOfRoster = new Roster(args.length];
for (int i = 0; i < args.length; i++)
System.out.println("Arg #" + i + " = " + args[i]);
Roster[i] = new Roster(args[i]); //declare & initialize a 1-dimensional array
Also, is this all the code necessary to get input from the command line, and could you maybe take a wee small second to explain the logic behind reading input from the command line, e.g., how does Java do it?
Thanks for your prompt assistance.