Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Student {
- private String name;
- private float mark;
- public static void main(String[] args) {
- Scanner stInput = new Scanner(System.in);
- System.out.print("Enter number of students:\n");
- int num = stInput.nextInt();
- stInput.nextLine();
- Student[] stGp = new Student[num];
- // info input
- for (int i = 0; i < num; i++) {
- System.out.print("Enter name and mark:\n");
- stGp[i] = new Student();
- stGp[i].name = stInput.nextLine();
- stGp[i].mark = stInput.nextInt();
- stInput.nextLine();
- }
- // average mark
- float sum = 0;
- for (Student aSt : stGp) {
- sum = sum + aSt.mark;
- }
- float average = sum / num;
- System.out.print("The average mark is " + average + "\n");
- // get the highest mark and name
- float highest = stGp[0].mark;
- String highestName = "";
- for (Student aSt : stGp) {
- if (aSt.mark > highest) {
- highest = aSt.mark;
- highestName = aSt.name;
- }
- }
- System.out.print("The highest mark and student is " + highestName + " " + highest + "\n");
- // list who above average
- System.out.print("Students whose mark scoring above average:\n");
- for (Student aSt : stGp) {
- if (aSt.mark >= average) {
- System.out.print(aSt.name + "\n");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment