int[] score = new int[3];
int score[]; // declares the array variable, allocating just 1 reference variable
score = new int[3]; // constructs the actual array, allocating 3 integer variables
char[] card;
String entries[];
int[] score = {100, 95, 97};
score = {100, 95, 97};
" on a line by itself, or score = 0;
"
[cpersiko@fog cs111a]$ java NameArray How many names do you want to enter? 3 Enter a name: Craig Enter a name: Serafina Enter a name: Tobias Here are the names you entered, in reverse order: Tobias Serafina Craig Here is the longest name, with 8 characters: Serafina [cpersiko@fog cs111a]$ java NameArray How many names do you want to enter? 6 Enter a name: Bob Enter a name: Jane Enter a name: Chi Hua Enter a name: Alfonso Enter a name: Andre Enter a name: Anna Here are the names you entered, in reverse order: Anna Andre Alfonso Chi Hua Jane Bob Here is the longest name, with 7 characters: Chi Hua [cpersiko@fog cs111a]$
void get_hours(int[] hours);
names = {"Craig", "Bassam", "Jennifer", "Melissa", "Anna"};
Please enter your name: Craig You are number 0 in the group Please enter your name: Bob You are not in the group Please enter your name: Jennifer You are number 2 in the group
System.out.println("You entered:"); for (i=0; i < inputNums.length; i++) System.out.print(inputNums[i] + " ");
System.out.println("You entered:"); for (double num : inputNums) System.out.print(num + " ");
-bash-3.2$ java SearchName usage: java SearchName Craig Bob Jane Ming: To search for a name in the list (Craig Bob Jane Ming) /* Sample Output: -bash-3.2$ java SearchName usage: java SearchName Craig Bob Jane Ming: To search for a name in the list (Craig Bob Jane Ming) -bash-3.2$ java SearchName Craig Bob Jane Ming Which name are you looking for? James Name not found. -bash-3.2$ java SearchName Janet Jack James John Which name are you looking for? jack jack is in the list. -bash-3.2$And here is the output for the program when it deletes the name:
[cpersiko@fog cs111a]$ java DeleteName Bassam Robert Ha Andy Korman Francisco Gloria Which name are you looking for? Robert Removing Robert from the list. Here are the remaining names: Bassam Ha Andy Korman Francisco Gloria [cpersiko@fog cs111a]$ java DeleteName Nicholas Francisco Elaine Joseph Which name are you looking for? Gloria Name not found. Here are the remaining names: Nicholas Francisco Elaine Joseph [cpersiko@fog cs111a]$ java DeleteName Nicholas Francisco Elaine Joseph Which name are you looking for? Joseph Removing Joseph from the list. Here are the remaining names: Nicholas Francisco Elaine [cpersiko@fog cs111a]$
Please enter 10 numbers: 5 4 3 2 1 5 6 7 8 9 Yes, the 5 is duplicated
Please enter 10 numbers: 4 3 2 1 2 3 5 6 7 8 No, the 4 is not duplicated
int[][] pixels = new int[480][640];
pixels[3][5] = 7;
pixels[5]
void clearScreen(int[][] p) { int x, y; for (y=0; y < p.length; y++) { for (x=0; x < p[y].length; x++) p[y][x] = 0; } }We would call the above function with the following function call:
clearScreen(pixels);
Col# : 0 1 2 3 4 5 6 7 8 910111213141516171819 Row 0: 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 Row 1: 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 Row 2: 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 Row 3: 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 Row 4: 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 Row 5: 0 0 0 0 0 1 0 0 0 0 0 0 0 0 2 0 0 0 0 0 Row 6: 0 0 0 0 0 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 Row 7: 0 0 0 0 0 0 0 1 0 0 0 0 2 0 0 0 0 0 0 0 Row 8: 0 0 0 0 0 0 0 0 1 0 0 2 0 0 0 0 0 0 0 0 Row 9: 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 Row 10: 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 Row 11: 0 0 0 0 0 0 0 0 2 0 0 1 0 0 0 0 0 0 0 0 Row 12: 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 Row 13: 0 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 0 0 Row 14: 0 0 0 0 0 2 0 0 0 0 0 0 0 0 1 0 0 0 0 0 Row 15: 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 Row 16: 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 Row 17: 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 Row 18: 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 Row 19: 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
for(double num : numArray)Here is some sample output:
[cpersiko@fog cs111a]$ java RemoveMax 98.5 74.2 105 55 98 88 Here are the numbers you entered, with the maximum removed: 98.5 74.2 55.0 98.0 88.0 [cpersiko@fog cs111a]$ java RemoveMax 10 9 8 7 6 5 4 3 2 1 0 Here are the numbers you entered, with the maximum removed: 9.0 8.0 7.0 6.0 5.0 4.0 3.0 2.0 1.0 0.0