-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathmultiDim.java
More file actions
48 lines (40 loc) · 1.25 KB
/
multiDim.java
File metadata and controls
48 lines (40 loc) · 1.25 KB
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
/*
Jacob John
*/
package assignment2;
import java.util.Scanner;
public class multiDim {
public static void main(String[] args) {
int i, j;
double t;
// Declaring 2-D array with 4 rows
int arr[][] = new int[4][];
// input for each batch
Scanner sc = new Scanner(System.in);
for (i = 0; i < arr.length; i++) {
System.out.print("Enter number of students for batch " + (i + 1) + ": ");
t = sc.nextDouble();
arr[i] = new int[(int) Math.ceil(t / 4)];
for (j = 0; j < arr[i].length; j++) {
if (t >= 4)
arr[i][j] = 4;
else
arr[i][j] = (int) t;
t = t - 4;
}
}
sc.close();
// Displaying the values of 2D Jagged array
int cfour = 0;
System.out.println("Contents of 2D Jagged Array");
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
if (arr[i][j] == 4)
cfour++;
}
System.out.println();
}
System.out.println("Number of tutors with 4 students are: " + cfour);
}
}