見つけ方:
- Javaの2D配列の行の最大値。
- Javaの2D配列の行の最小値。
- Javaの2D配列の列の最大値。
- Javaの2D配列の列の最小値。
import java.util.*;
class Example{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
System.out.print("Enter Number of Students : ");
byte a=input.nextByte();
System.out.print("Enter Number of Subjects : ");
byte b=input.nextByte();
System.out.println();
byte[][] st=new byte[a][b];
//Input Marks for Subjects for different Students
for(byte i=0;i<a;i++){
System.out.println("Enter Subject Marks for Student "+(i+1)+" :- ");
for(byte x=0;x<b;x++){
System.out.print("\tEnter Marks % for Subject "+(x+1)+" : ");
st[i][x]=input.nextByte();
}
System.out.println();
}
//Find Student Total
int[] studTotal=new int[a];
for(byte i=0;i<a;i++){
for(byte x=0;x<b;x++){
studTotal[i]=studTotal[i]+st[i][x];
}
}
//Find Student Average
float[] studAvg=new float[a];
for(byte i=0;i<a;i++){
for(byte x=0;x<b;x++){
studAvg[i]=(float)studTotal[i]/b;
studAvg[i]=Math.round(studAvg[i]*100)/(float)100;
}
}
//Find Student Grade
char[] studGrade=new char[a];
for(byte i=0;i<a;i++){
if(studAvg[i]>=75){
studGrade[i]='A';
}else if(studAvg[i]>=65){
studGrade[i]='B';
}else if(studAvg[i]>=55){
studGrade[i]='C';
}else if(studAvg[i]>=35){
studGrade[i]='D';
}else{
studGrade[i]='F';
}
}
//Find Student Maximum
byte[] studMax=new byte[a];
for(byte i=0;i<a;i++){
studMax[i]=st[i][0];//<<==Problem-Solved==>>
for(byte x=0;x<b;x++){
if(st[i][x]>studMax[i]){
studMax[i]=st[i][x];
}
}
}
//Find Student Minimum
byte[] studMin=new byte[a];
for(byte i=0;i<a;i++){
studMin[i]=st[i][0];//<<==Problem-Solved==>>
for(byte x=0;x<b;x++){
if(st[i][x]<studMin[i]){
studMin[i]=st[i][x];
}
}
}
//Display Information in a Table
for(byte i=0;i<a;i++){
for(byte x=0;x<b;x++){
System.out.print(st[i][x]+"\t");
}
//Display Student's Total, Average, Grade, Maximum, Minimum
System.out.print(studTotal[i]);
System.out.print("\t"+studAvg[i]);
System.out.print("\t"+studGrade[i]);
System.out.print("\t"+studMax[i]);
System.out.print("\t"+studMin[i]);
System.out.println();
}
}
}