-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArrayExample.java
More file actions
50 lines (39 loc) · 783 Bytes
/
ArrayExample.java
File metadata and controls
50 lines (39 loc) · 783 Bytes
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
package Pack1;
import java.util.Random;
public class Array2 {
public static void main(String[] args)
{
Random rnd = new Random();
int total=0;
int[] totalArr=new int[4];
int [] [] array1= new int[4][4];
for(int i=0; i<4;i++)
{
for(int j=0; j<4; j++)
{
array1[i][j]=rnd.nextInt(9)+1;
}
}
for (int i=0; i<4;i++)
{
System.out.print(i+1+".Line ");
for(int j=0; j<4; j++)
{
System.out.print(array1[i][j]+" "); //Shows the array elements
total+=array1[i][j];
}
System.out.println("Total: "+total);
total=0;
}
System.out.print("Total: ");
for(int i=0; i<4;i++)
{
for(int j=0; j<4;j++)
{
totalArr[i]+=array1[j][i];
}
System.out.print(totalArr[i]+" ");
total=0;
}
}
}