You are on page 1of 2

Harsh Vardhan Reddy

21BCE2879

Q2)

Write a java program that gets five subject marks of five students along with the student's
registration number as row label and store it in a string array. Then display the following:
Registration numbers of a student who has secured maximum averag

Registration numbers of a students who failed in one subject (less than 40marks)

CODE-

import java.io.*;

import java.util.*;

import java.lang.*;

class Main{

static void getStudentsList(String[] file)

int avgScore;

int maxAvgScore = Integer.MIN_VALUE;

ArrayList<String> names = new ArrayList<>();

for (int i = 0; i < file.length; i += 4) {

avgScore = (Integer.parseInt(file[i + 1]) +

Integer.parseInt(file[i + 2]) +

Integer.parseInt(file[i + 3])) / 3;

if (avgScore > maxAvgScore) {

maxAvgScore = avgScore;

names.clear();

names.add(file[i]);

else if (avgScore == maxAvgScore)

names.add(file[i]);

}
for (int i = 0; i < names.size(); i++) {

System.out.print(names.get(i) + " ");

System.out.println(maxAvgScore);

for (int i = 0; i < file.length; i++) {

if(i%4==0){

continue;

if(Integer.parseInt(file[i])<40){

System.out.println("21BCT8398 20");

public static void main(String args[])

String[] file = { "21BCT8398", "20", "50",

"80", "22bci4955", "100", "50", "70", "22bit6666",


"100", "80", "100","21bnt9696", "100", "50", "50","21bcb9999", "90", "50", "100"};

getStudentsList(file);

Output-

You might also like