Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
57 lines (40 loc) · 1.57 KB

File metadata and controls

57 lines (40 loc) · 1.57 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Manually allocate differing size second dimensions.
// Note that one dimensional array is arranged in "rows", not columns. See the textbook page on 164.
// One dimensional array: type [row];
// Two dimensional array: type [column][row];
public class Ragged {
public static void main(String[] args) {
// An array that stores the number of passengers that ride an airport shuttle during a week.
int riders [][] = new int [7][];
riders[0] = new int[10]; // the shuttle runs 10 times a day during every weekday.
riders[1] = new int[10]; // Tuesday.
riders[2] = new int[10]; // Wednesday.
riders[3] = new int[10]; // Thursday.
riders[4] = new int[10]; // Friday.
riders[5] = new int[2]; // the shuttle runs twice a day on Saturday and Sunday.
riders[6] = new int[2]; // Sunday.
// After finishing the skeleton of the table for recording, we start to collect the data into the table(array).
int i, j;
// fabricate some fake data.
for(i = 0; i < 5; i++)
for(j = 0 ; j < 10 ; j++)
riders[i][j] = i + j + 10;
System.out.println("Riders per trip during the workweek: ");
for(i = 0; i < 5 ; i++) {
for(j = 0; j < 10; j++)
System.out.print( riders[i][j] + " ");
System.out.println();
}
System.out.println();
// fabricate some fake data.
for(i = 5; i < 7 ; i++)
for(j = 0; j < 2 ; j++)
riders[i][j] = i + j + 10 ;
System.out.println("Riders per trip on the weekend: ");
for(i = 5; i < 7; i++) {
for (j = 0; j < 2; j++)
System.out.print(riders[i][j] + " ");
System.out.println();
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.