Advertisement
desislava_topuzakova

Untitled

Feb 28th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Grades {
  4. public static void main(String[] args) {
  5. Scanner scanner=new Scanner(System.in);
  6. int students=Integer.parseInt(scanner.nextLine());
  7. double fail=0;
  8. double from3=0;
  9. double from4=0;
  10. double top=0;
  11. double sum=0;
  12. for (int i = 1; i <=students ; i++)
  13. {double grade=Double.parseDouble(scanner.nextLine());
  14. sum=sum+grade;
  15. if(grade>=5){top++;}
  16. else if(grade>=4&&grade<=4.99){from4++;}
  17. else if(grade>=3&&grade<=3.99){from3++;}
  18. else if(grade<3){fail++;}}
  19. double average=(double)sum/students;
  20. double per_top=((double)(top/students))*100;
  21. double per_from4=((double)(from4/students))*100;
  22. double per_from3=((double)(from3/students))*100;
  23. double per_fail=((double)(fail/students))*100;
  24.  
  25. System.out.print("Top students: ");
  26. System.out.printf("%.2f",per_top);
  27. System.out.println("%");
  28. System.out.print("Between 4.00 and 4.99: ");
  29. System.out.printf("%.2f",per_from4);
  30. System.out.println("%");
  31. System.out.print("Between 3.00 and 3.99: ");
  32. System.out.printf("%.2f",per_from3);
  33. System.out.println("%");
  34. System.out.print("Fail: ");
  35. System.out.printf("%.2f",per_fail);
  36. System.out.println("%");
  37. System.out.print("Average: ");
  38. System.out.printf("%.2f",average);
  39.  
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement