You are on page 1of 2

The public keyword is an access specifier, which allows the programmer to contro l the visibility of class members.

main( ) is the method called when a Java application begins. String args[ ] declares a parameter named args, which is an array of instances of the c lass String. (Arrays are collections of similar objects.) Objects of type String store charac ter strings. In this case, args receives any command-line arguments present when the program is execu ted. System.out.print("The value of num * 2 is "); System.out.println(num); Several new things are occurring here. First, the built-in method print( ) is us ed to display the string The value of num * 2 is . This string is not followed by a newline. Thi s means that when the next output is generated, it will start on the same line. The prin t( ) method is just like println( ), except that it does not output a newline character after e ach call.

KEYWORDS PAGE 32 Java defines eight primitive types of data: byte, short, int, long, char, float, double, and boolean.

// Manually allocate differing size second dimensions. class TwoDAgain { public static void main(String args[]) { int twoD[][] = new int[4][]; twoD[0] = new int[1]; twoD[1] = new int[2]; twoD[2] = new int[3]; twoD[3] = new int[4]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<i+1; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<i+1; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } } This program generates the following output: 0 1 2 3 4 5

6 7 8 9

You might also like