From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch10;
02
03 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
04
05 importimport means to make the classes and/or packages available in this program fang2.core.Game;
06 importimport means to make the classes and/or packages available in this program fang2.util.InitializeApplication;
07
08 /**
09 * Read unnamed arguments, print out the first argument one character
10 * per line. Demonstrates how a String is a collection of charchar is the type for a single letter or symbol and it is short for character.
11 */
12 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects ArgumentCharacters
13 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
14 /**
15 * If there are any unnamed command-line parameters, then get the
16 * first one and print out the characters, one per line. If there are
17 * no parameters, print out a message to that effect.
18 */
19 @Override
20 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
21 System.out.println(getClass().getName());
22 ArrayList<String> args =this assignment operator makes the left side equal to the right side InitializeApplication.getUnnamedArgs();
23 ifif executes the next statement only if the condition in parenthesis evaluates to true (args.isEmpty()) {open braces start code blocks and must be matched with a close brace
24 System.out.println(" No unnamed argument provided");
25 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
26 String firstArgument =this assignment operator makes the left side equal to the right side args.get(0);
27 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i !=this is the not equals operator which evaluates to true if both sides are different firstArgument.length(); ++this is the increment operator, which increases the variable by 1i) {open braces start code blocks and must be matched with a close brace
28 System.out.println(" str.charAt(" +adds two numbers together or concatenates Strings together i +adds two numbers together or concatenates Strings together ") = '" +adds two numbers together or concatenates Strings together
29 firstArgument.charAt(i) +adds two numbers together or concatenates Strings together "'");
30 }close braces end code blocks and must match an earlier open brace
31 }close braces end code blocks and must match an earlier open brace
32 }close braces end code blocks and must match an earlier open brace
33 }close braces end code blocks and must match an earlier open brace
34
35 //Uploaded on Mon Mar 29 21:42:26 EDT 2010
|
Download/View scg/ch10/ArgumentCharacters.java