-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxValue.java
More file actions
51 lines (50 loc) · 1.21 KB
/
MaxValue.java
File metadata and controls
51 lines (50 loc) · 1.21 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
// Program: Find Maximum Value in a 2D Array
// Topic: 2D Arrays
// Description: Reads elements into a 2x2 integer matrix, displays the matrix, and finds the largest element.
// Demonstrates nested loops, enhanced for-loops, and comparison logic to identify the maximum value.
package Array2D;
import java.util.*;
/**
*
* @author Samim
*/
public class MaxValue
{
public static int[][] input()
{
int ar[][]=new int[2][2];
Scanner sc=new Scanner(System.in);
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
ar[i][j]=sc.nextInt();
}
}
return ar;
}
public static void main(String args[])
{
int ar[][]=input();
int MaxValue=ar[0][0];
for(int[]row:ar)
{
for(int element :row)
{
if(element >MaxValue)
{
MaxValue=element;
}
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.print(ar[i][j]+" ");
}
System.out.println();
}
System.out.println("Max Value :"+MaxValue);
}
}