Answer to Question #235337 in Java | JSP | JSF for Don

Question #235337
Write a console application that will display the student who has the lowest result from a class
list. The program must prompt a user to enter in the amount of students in the class and then
proceed to capture each student name and result for an assessment. Once all the student details
have been captured, display the student with the lowest result.
1
Expert's answer
2021-09-09T17:13:40-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		System.out.println("Enter number of students: ");
		int n=in.nextInt();
		
		int [] scores=new int [n];
		String [] names=new String [n];
		for (int i=0;i<n;i++){
		    System.out.println("Enter name and score of student "+(i+1)+": ");
		    names[i]=in.next();
		    scores[i]=in.nextInt();
		    
		}
		int min=scores[0];
		String m_name="";
		for(int i=0;i<n;i++){
		    if (scores[i]<min){
		        min=scores[i];
		        m_name=names[i];
		    }
		}
		System.out.println("The student with the lowest result has the following details:");
		System.out.println("Name: "+m_name+"\nScore: "+min);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS