fork download
  1. import java.io.*;
  2. import java.lang.System.*;
  3. import java.io.IOException;
  4. import java.util.Random;
  5. import java.util.Arrays;
  6.  
  7. public class NumberArray {
  8. public static void main(String args[]) throws IOException {
  9.  
  10. System.out.println("Created By You\n");
  11. System.out.println("This Program generates 2 random numbers fifty times ");
  12. System.out.println("Automically sum up all the 10th number and add all the 50 numbers");
  13.  
  14. int sumTotal = 0; //total sum of all 100 number
  15. int tenthTotal = 0; //total all tenth number
  16. final int ARRAYSIZE = 51;
  17.  
  18. // Create array of ints
  19. int[] intValues = new int[ARRAYSIZE];
  20. // Assign random values up to 99
  21. for (int i=1; i<intValues.length; i++) {
  22. intValues[i] = (int) (Math.random() * 100);
  23. sumTotal += intValues[i];
  24. }
  25.  
  26. // Display the results
  27. System.out.println("Random Number Values");
  28. for (int i=1; i<intValues.length; i++) {
  29.  
  30. System.out.println(intValues[i]);
  31. // Print new line every 10 items
  32. if ((i % 10) == 0) {
  33. System.out.print("The 10th Number is: " + intValues[i]); //display the 10th number
  34. tenthTotal += intValues[i]; //add each 10th number
  35. System.out.println(" ");
  36. }
  37. }
  38.  
  39. System.out.println("Sum of 10th numbers" + tenthTotal);
  40. System.out.println("Sum of all 50 numbers" + sumTotal);
  41. System.out.println("Exit");
  42. System.exit(0);
  43. }
  44. }
  45.  
  46.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: class NumberArray is public, should be declared in a file named NumberArray.java
public class NumberArray {
       ^
1 error
stdout
Standard output is empty