-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraysPractice.java
More file actions
82 lines (66 loc) · 1.67 KB
/
Copy pathArraysPractice.java
File metadata and controls
82 lines (66 loc) · 1.67 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package tryingsomething;
import java.util.Scanner;
/**
* Created by rmukherj on 8/8/16.
* Given an arry A of N integers, print each element in reverse order as a single line of
* space separated integers.
*/
public class ArraysPractice {
public static void main(String[] args){
/*
The below function is take the number of inouts into an array as per console.readline
and then print reverse.
*/
Scanner s = new Scanner(System.in);
int size = s.nextInt();
s.nextLine();
int a[] = new int[size];
for(int i=0;i<size;i++){
a[i]= s.nextInt();
}
for(int i=size-1;i>0;i--){
System.out.println(a[i]+" ");
}
System.out.println(a[0]);
/*
2D Array
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 9 2 -4 -4 0
0 0 0 -2 0 0
0 0 -1 -2 -4 0
*/
int arr[][] = new int[6][6];
Scanner sin = new Scanner(System.in);
int max = -10000;
for (int i=0;i<6;i++)
{
for(int j =0 ;j<6;j++)
{
arr[i][j] = sin.nextInt();
}
}
for (int i=0;i<4;i++)
{
for(int j =0 ;j<4;j++)
{
int output = sum(arr,i,j);
max = max > output ? max: output ;
}
}
System.out.println(max);
}
public static int sum(int[][] a,int i,int j)
{
int sum;
sum = a[i][j] +
a[i][j+1] +
a[i][j+2] +
a[i+1][j+1] +
a[i+2][j] +
a[i+2][j+1] +
a[i+2][j+2];
return sum;
}
}