Advertisement
Parasect

[UNIEX] 6

Nov 24th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class apples {
  4.  
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7. int range = (40 - 20) + 1; // assuming that each class has 20 to 40 students
  8.  
  9. int shihva1 = 0;
  10. int shihva2 = 0;
  11. int shihva3 = 0;
  12. int countinput = 1;
  13. while (countinput <= 12) {
  14. System.out.println("students in grade's 7 classes: ");
  15. while (countinput <= 4) {
  16. double r = (Math.random() * range) + 20;
  17. System.out.print((int) r + " ");
  18. shihva1 += r;
  19. countinput++;
  20. }
  21. System.out.println();
  22. System.out.println("students in grade's 8 classes: ");
  23. while (countinput <= 8 && countinput > 4) {
  24. double r = (Math.random() * range) + 20;
  25. System.out.print((int) r + " ");
  26. shihva2 += r;
  27. countinput++;
  28. }
  29. System.out.println();
  30. System.out.println("students in grade's 9 classes: ");
  31. while (countinput <= 12 && countinput > 8) {
  32. double r = (Math.random() * range) + 20;
  33. System.out.print((int) r + " ");
  34. shihva3 += r;
  35. countinput++;
  36. }
  37. }
  38. System.out.println();
  39. System.out.println("Sum for grade 7: " + shihva1
  40. + "\nSum for grade 8: " + shihva2 + "\nSum for grade 9: "
  41. + shihva3);
  42. System.out.println("Sum for school: " + (shihva1 + shihva2 + shihva3));
  43. in.close();
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement