Well, the great thing with java, is there is a lot of programs you can use to find stuff like this. java.lang.Math can easily do mins and maxes.
so for instance
//something like this
int max = 0, min = 100;
int num = /*a value*/;
if(num < min){
min = num;
}
if(num > max){
max = num;
}
//becomes
int max = 0, min = 100;
int num = /*a value*/
max = Math.max(max, num);
min = Math.min(min, num);
/**
* It's just a bit faster and easier
* and should alleviate some of the errors you are getting
**/
I ran your code, with the same test params. I will star the inccorect values.
Input No of student : 3
Input No of subjects : 3
Input marks for student 0:
subect 0:60
subect 1:50
subect 2:70
Input marks for student 1:
subect 0:80
subect 1:70
subect 2:60
Input marks for student 2:
subect 0:50
subect 1:70
subect 2:8
Marks Max Min Total Avrg Grade
60 50 70 70 50 180 60 C
80 70 60 80 *50 210 70 B
50 70 8 *80 8 128 42 D
190 80 50 190 80 50 138 80 8
You can try moving where where you actually initiate the variables in to the following for loop. As for the vertical calculations, you didn't finish it and you didn't put comments into your code, so until you explain what you don't understand with the vertical portion or add comments so that it is easier to follow your logic, there isn't much I can do other than help fix your existing code.
I marked what I saw was wrong or poor. You can make changes where and if you want.
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();
}
}
//close the scanner after you're done with it.
input.close();
System.out.println("Marks Max Min Total Avrg Grade");//hit the tab key or use the \t command here, it's neater than pressing space.
int max = marks[0][0];//initiate them here
int min = marks[0][0];
int max2 = marks[0][0];
int min2 = marks[0][0];
int avg = 0;
char grade = '0';
for (int m = 0; m < marks.length; m++)
{ //reset them each time here.
int total = 0;
for (int n = 0; n < marks[m].length; n++){
if (max < marks[m][n]){ //max = Math.max(max, marks[m][n]);
max = marks[m][n];
}
if (min > marks[m][n]){ //min = Math.min(min, marks[m][n]);
min = marks[m][n];
}
total += marks[m][n];
avg = total/marks[m].length;//change marks[m].length to su. It's easier to follow.
if (avg >= 75){
grade = 'A';
}
else if ((avg >= 65) & (avg < 75)){//don't need & (avg<75)
grade= 'B';
}
else if ((avg >= 55)& (avg < 65)){//don't need (avg<65) same for the next one
grade = 'C';
}
else if((avg >= 35)& (avg < 55)){
grade= 'D';
}
else{
grade = 'F';
}
System.out.print(marks[m][n]+ " ");
}
System.out.print(max + "\t" + min+ "\t");
System.out.print(total +"\t"+ avg + "\t"+ grade);
System.out.println( );
}
// ------------------------------------------------------------------------------------------------
/**
* Can't help here until you finish or explain what exactly you don't understand
* I'm willing to help, but you gotta help me help you.
*/
for (int m = 0; m < st; m++)
{
int total2 = 0;
for (int n = 0; n < su; n++){
if (max2 < marks[n][m]){
max2 = marks[n][m];
}
if (min2 > marks[n][m]){
min2 = marks[n][m];
}
total2 += marks[n][m];
System.out.print(marks[m][n]+ " ");
}
System.out.println();
System.out.print(total2 + " " + max2 + " "+ min2+ " ");
}
}