94 lines
2.8 KiB
Java
94 lines
2.8 KiB
Java
|
import java.util.Scanner;
|
||
|
|
||
|
class StuRes {
|
||
|
|
||
|
int[][] marks = new int[3][3];
|
||
|
int[] totalMarks = new int[3];
|
||
|
int[] rollNumbers = new int[3];
|
||
|
|
||
|
void storeMarks(int[][] studentMarks) {
|
||
|
for (int i = 0; i < 3; i++) {
|
||
|
System.arraycopy(studentMarks[i], 0, marks[i], 0, 3);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void calculateTotalMarks() {
|
||
|
for (int i = 0; i < 3; i++) {
|
||
|
totalMarks[i] = 0;
|
||
|
for (int j = 0; j < 3; j++) {
|
||
|
totalMarks[i] += marks[i][j];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void findHighestMarksInSubjects() {
|
||
|
for (int subject = 0; subject < 3; subject++) {
|
||
|
int highestMark = marks[0][subject];
|
||
|
int highestRollNo = rollNumbers[0];
|
||
|
for (int student = 1; student < 3; student++) {
|
||
|
if (marks[student][subject] > highestMark) {
|
||
|
highestMark = marks[student][subject];
|
||
|
highestRollNo = rollNumbers[student];
|
||
|
}
|
||
|
}
|
||
|
System.out.println(
|
||
|
"Highest mark in Subject " +
|
||
|
(subject + 1) +
|
||
|
": " +
|
||
|
highestMark +
|
||
|
" (Roll No: " +
|
||
|
highestRollNo +
|
||
|
")"
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void findHighestTotalMarks() {
|
||
|
int highestTotal = totalMarks[0];
|
||
|
int highestRollNo = rollNumbers[0];
|
||
|
for (int i = 1; i < 3; i++) {
|
||
|
if (totalMarks[i] > highestTotal) {
|
||
|
highestTotal = totalMarks[i];
|
||
|
highestRollNo = rollNumbers[i];
|
||
|
}
|
||
|
}
|
||
|
System.out.println(
|
||
|
"Highest total marks: " +
|
||
|
highestTotal +
|
||
|
" (Roll No: " +
|
||
|
highestRollNo +
|
||
|
")"
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
Scanner scanner = new Scanner(System.in);
|
||
|
StuRes studentResults = new StuRes();
|
||
|
int[][] studentMarks = new int[3][3];
|
||
|
|
||
|
System.out.println("Enter details for 3 students:");
|
||
|
for (int i = 0; i < 3; i++) {
|
||
|
System.out.print("Enter Roll Number for Student " + (i + 1) + ": ");
|
||
|
studentResults.rollNumbers[i] = scanner.nextInt();
|
||
|
System.out.println(
|
||
|
"Enter marks for Student with Roll No " +
|
||
|
studentResults.rollNumbers[i] +
|
||
|
":"
|
||
|
);
|
||
|
for (int j = 0; j < 3; j++) {
|
||
|
System.out.print("Subject " + (j + 1) + ": ");
|
||
|
studentMarks[i][j] = scanner.nextInt();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
studentResults.storeMarks(studentMarks);
|
||
|
studentResults.calculateTotalMarks();
|
||
|
|
||
|
System.out.println("\nResults:");
|
||
|
studentResults.findHighestMarksInSubjects();
|
||
|
studentResults.findHighestTotalMarks();
|
||
|
|
||
|
scanner.close();
|
||
|
}
|
||
|
}
|