Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class apples {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int range = (40 - 20) + 1; // assuming that each class has 20 to 40 students
- int shihva1 = 0;
- int shihva2 = 0;
- int shihva3 = 0;
- int countinput = 1;
- while (countinput <= 12) {
- System.out.println("students in grade's 7 classes: ");
- while (countinput <= 4) {
- double r = (Math.random() * range) + 20;
- System.out.print((int) r + " ");
- shihva1 += r;
- countinput++;
- }
- System.out.println();
- System.out.println("students in grade's 8 classes: ");
- while (countinput <= 8 && countinput > 4) {
- double r = (Math.random() * range) + 20;
- System.out.print((int) r + " ");
- shihva2 += r;
- countinput++;
- }
- System.out.println();
- System.out.println("students in grade's 9 classes: ");
- while (countinput <= 12 && countinput > 8) {
- double r = (Math.random() * range) + 20;
- System.out.print((int) r + " ");
- shihva3 += r;
- countinput++;
- }
- }
- System.out.println();
- System.out.println("Sum for grade 7: " + shihva1
- + "\nSum for grade 8: " + shihva2 + "\nSum for grade 9: "
- + shihva3);
- System.out.println("Sum for school: " + (shihva1 + shihva2 + shihva3));
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement