Breaking

Monday 6 November 2017

Sort Pass Students by Name


                      Sort Pass Students by Name

A list of N students name and their marks in three subjects are passed as the input. The average of the 3 subjects must be greater than or equal to 40 and also the total marks must be greater than or equal to 150 for the student to pass. Print the names of the students who have passed, with the names sorted in ascending order.
Input Format:
The first line contains N, the number of students.
The following N lines contains Name and marks of each student in three subjects separated by space.
Output Format:
Print the names of the students who passed (with the names sorted in ascending order).
Example Input/Output 1:
Input:
3
Ram 45 65 45
Geetha 60 30 50
Soundarya 80 90 80
Output:
Ram
Soundarya


Code:

import java.util.*;
public class Hello {

    public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int m1,m2,m3,n,i,tot,avg;
String nm;
n=sc.nextInt();
List<String> li=new ArrayList<String>();
for(i=0;i<n;i++)
{
    nm=sc.next();
    m1=sc.nextInt();
    m2=sc.nextInt();
    m3=sc.nextInt();
    tot=m1+m2+m3;
    avg=tot/3;
    if(tot>=150&&avg>=40)
        li.add(nm);
}
Collections.sort(li);
for(String s:li)
    System.out.println(s);


}
}

Please do comment If u have any Queries!

No comments:

Post a Comment

Like