vendredi 13 novembre 2020

Program to generate and sum random integers(1-10)

I'm trying to make a program to generate 10 integers from 1-10 OR stop once the sum reaches 40. What is wrong with my code? and how can I fix it?

Random integers = new Random();
       for (int i=0;i<10;i++) {
           integer = integers.nextInt(10)+1;
           System.out.println(integer);
       sum = sum + integer;
       }while (sum >=40)
    System.out.println("Sum is " +sum);
}



Aucun commentaire:

Enregistrer un commentaire