Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Grades {
- public static void main(String[] args) {
- Scanner scanner=new Scanner(System.in);
- int students=Integer.parseInt(scanner.nextLine());
- double fail=0;
- double from3=0;
- double from4=0;
- double top=0;
- double sum=0;
- for (int i = 1; i <=students ; i++)
- {double grade=Double.parseDouble(scanner.nextLine());
- sum=sum+grade;
- if(grade>=5){top++;}
- else if(grade>=4&&grade<=4.99){from4++;}
- else if(grade>=3&&grade<=3.99){from3++;}
- else if(grade<3){fail++;}}
- double average=(double)sum/students;
- double per_top=((double)(top/students))*100;
- double per_from4=((double)(from4/students))*100;
- double per_from3=((double)(from3/students))*100;
- double per_fail=((double)(fail/students))*100;
- System.out.print("Top students: ");
- System.out.printf("%.2f",per_top);
- System.out.println("%");
- System.out.print("Between 4.00 and 4.99: ");
- System.out.printf("%.2f",per_from4);
- System.out.println("%");
- System.out.print("Between 3.00 and 3.99: ");
- System.out.printf("%.2f",per_from3);
- System.out.println("%");
- System.out.print("Fail: ");
- System.out.printf("%.2f",per_fail);
- System.out.println("%");
- System.out.print("Average: ");
- System.out.printf("%.2f",average);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement