Simple Student Mark List
import java.util.Scanner; public class Array2DstudentsMarks { Scanner scn = new Scanner(System.in); String stud[]; int[][] marks; int[] tot, highestScorer; int subj, totHighStud; public static void main(String[] args) { // STUDENTS MARKS WITH TOTAL - 2D ARRAY Array2DstudentsMarks twoDArray = new Array2DstudentsMarks(); twoDArray.studentMarksTotal(); twoDArray.dispMarkAndTotal(); } private void studentMarksTotal() { System.out.println("Enter no. of Students"); int n = scn.nextInt(); System.out.println("Enter no. of Subjects"); subj = scn.nextInt(); stud = new String[n]; marks = new int[n][subj]; tot = new int[n]; highestScorer= new int[subj]; int maxTot = 0, highScore=0; for (int i=0; i<n; i++) { System.out.println("Enter Student name."); stud[i] = scn.next(); System.out.println("Enter "+subj+" subjects marks of "+stud[i]+" one by one."); for (int j=0; j<subj; j++) { marks[i][j] = scn.nextInt(); tot[i] += marks[i][j]; if (marks[highestScorer[j]][j] < marks[i][j]) { highestScorer[j] = i; //highScore = marks[i][j]; } } if (maxTot < tot[i]) { maxTot = tot[i]; totHighStud = i; } } } private void dispMarkAndTotal() { System.out.println("------------------------------------------------------------------------"); System.out.println(" STUDENTS MARK LIST "); System.out.println("------------------------------------------------------------------------"); for (int i=0; i<stud.length; i++) { System.out.println("Student Name : "+stud[i]); for (int j=0; j<subj; j++) { System.out.println("Subject-"+(j+1)+" = "+marks[i][j]); } System.out.println(); System.out.println("Total Marks = "+tot[i]); System.out.println("Percentage = "+(tot[i]/subj)+ "%"); System.out.println("------------------------------------------------------------------------"); } for (int i=0; i<highestScorer.length; i++) { int student = highestScorer[i]; System.out.println("Subject-"+(i+1)+" Highest Mark is "+marks[student][i]+" achieved by "+stud[student]); } System.out.println("------------------------------------------------------------------------"); System.out.println("Over All Highest Total "+tot[totHighStud]+" achieved By "+stud[totHighStud]); System.out.println("------------------------------------------------------------------------"); } }
OUTPUT: