2551.CommandLineInput.Fall2005 - main. The String args is...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Assignment Help #3 – Command Line Inputs for Program #3 Command line inputs are quite simple in Java and are almost identical to those used in C. Here’s the scoop: When you start to execute your program, you normally issue: $ java executableProgram.class Now, if we were to input, say, a string value plus an integer, we’d issue something like: $ java executableProgram.class yourNameString someIntegerValue e.g. $ java Computation Felius_T_Schmuck 52 <enter> So, you have invoked the executable (actually, you are linking and then executing…) and passing two parameters. Remember, anything entered like this is a string . SO, if you want the 52 to be an integer, say, internally, you will need to use the Integer.parseInt (…. .) to convert that string 52 into an integer, 52 – just as you did before. If the name is to be treated as a name, then no conversion is necessary. So, how do we GET to these puppies? Remember, we have public static void main (String [] args) This String [] args constitutes the arguments (as usual) to a method,
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: main. The String args is an array of strings! But so far, we did not use command line inputs. Since arrays (in this context) start with an index of zero (0), to get to the first input argument, namely, Felius_T_Schmuck, symbolically referred to as arg[0], wed say: String name; name = args[0]; and the input string is assigned to name. args[0] references the first command line input after the file name to be executed. For the integer, wed have to say: int age; age = Integer.parseInt (args[1]); This takes the second string input and converts it to an integer (you know this) and assigns it to an integer variable, age. If there were three command line inputs, the next one would be referred to as args[2], and it might or might not have to be converted internally depends if it is a string (no conversion) or a numeric type some conversion to integer, float, double, char, etc. Got it? Hope so. Good luck....
View Full Document

This note was uploaded on 07/26/2011 for the course COP 2551 taught by Professor Roggio,r during the Summer '08 term at UNF.

Page1 / 2

2551.CommandLineInput.Fall2005 - main. The String args is...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online