fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println("Solving question 1:\n");
  13. solveQ1();
  14. }
  15.  
  16. public static void solveQ1() {
  17. int [] max = new int[5];
  18. int [] min = new int[5];
  19. for (int i=0; i < max.length; i++) {
  20. max[i] = Integer.MIN_VALUE;
  21. min[i] = Integer.MAX_VALUE;
  22. }
  23. int [] q1 = new int[5];
  24.  
  25. for (int i=0; i<=1000000; i++) {
  26. q1[0] = ( int ) ( Math.random( ) * 30 ) + 20 ;
  27. q1[1] = ( int ) ( Math.random( ) * 20 ) + 30 ;
  28. q1[2] = ( int ) ( Math.random( ) * 10 ) + 40 ;
  29. q1[3] = ( int ) ( Math.random( ) * 20 );
  30. q1[4] = ( int ) ( Math.random( ) * 25 ) + 25 ;
  31. for(int j = 0; j < q1.length; j++) {
  32. if(min[j] > q1[j]) {
  33. min[j] = q1[j];
  34. }
  35. if(max[j] < q1[j]) {
  36. max[j] = q1[j];
  37. }
  38. }
  39. }
  40. for(int i=0; i < q1.length; i++) {
  41. System.out.println("Answer " + ((char)('a' + i)) + " yields min: " + min[i] +
  42. " and max: " + max[i] + " and is: " +
  43. (((min[i]==20) && (max[i] == 49)) ? "correct" : "wrong"));
  44. }
  45. }
  46. }
Success #stdin #stdout 0.5s 320512KB
stdin
Standard input is empty
stdout
Solving question 1:

Answer a yields min: 20 and max: 49 and is: correct
Answer b yields min: 30 and max: 49 and is: wrong
Answer c yields min: 40 and max: 49 and is: wrong
Answer d yields min: 0 and max: 19 and is: wrong
Answer e yields min: 25 and max: 49 and is: wrong