Hi Guys
I'm trying to find max and min values of 2D array. I managed to get the right out put for MAX, But MIN value does not come correct.
Please help me. my code is below -
Regards
Rayan
import java.util.*; class sq{ public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Input No of student : "); int st = input.nextInt(); System.out.print("Input No of subjects : "); int su = input.nextInt(); int [][] marks = new int[st][su]; for (int i = 0; i < marks.length; i++){ System.out.println("Input marks for student "+i+":" ); for (int j = 0; j < marks[i].length; j++){ System.out.print("subect "+j+":"); marks[i][j] = input.nextInt(); } } for (int m = 0; m < marks.length; m++) { int max = marks[0][0]; int min = marks[0][0]; for (int n = 0; n < marks[m].length; n++){ if (max < marks[m][n]){ max = marks[m][n]; if (min > marks[m][n]){ min = marks[m][n]; } System.out.print(marks[m][n]+" "); } System.out.print(" " + max + " " + min ); System.out.println( ); } } }