Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do an addition from random numbers by the user?
    text
    copied!<p>I am new to Java and I would like some help. I have to solve this problem and I have it almost 90% solved:</p> <ol> <li>Prompt the user to enter number of students. It must be a number that is perfectly divisible by 10 i.e. (number % 10) = 0</li> <li>Check user input. If user input is not divisible by 10, keep asking the user for input until he enter a right number.</li> <li>Accept user input and generate that many random numbers in the range from 0 to 100.</li> <li>Print a matrix of random numbers and calculate the sum and average of all these random numbers and print them to the user.</li> <li>Format sum and average to three decimal points.</li> </ol> <p>This is my code so far:</p> <pre><code>import java.text.DecimalFormat; import java.util.Scanner; public class Calculator10 { public static void main(String[] args) { Scanner user_input = new Scanner(System.in); int num; do { System.out.print("Enter a number: "); num = user_input.nextInt(); } while(num % 10 != 0); double numb; DecimalFormat dec = new DecimalFormat("0.00"); for (int i=0; i&lt;num; i++){ numb = Math.abs(Math.random() * ( 0 - 100 )); System.out.print(" " +dec.format(numb) + " "); } } } </code></pre> <p>As you can see, I have solved until the first part of # 4. I am not sure how I could sum all those random numbers displayed on the screen after user input. Of course, we have to store them in an array but I tried to do that but couldn't. So, how could I complete step #4 and 5? I would appreciate any help. Thanks a lot guys.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload