Advertisement
CyrusVerkest

E7.1

Nov 10th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. A)
  2. import java.util.Random;
  3.  
  4.  
  5. public class E1 {
  6.  
  7.     public static void main(String[] args) {
  8.         int[] rando = new int[10];
  9.         Random randomGenerator = new Random();
  10.         int total = 0;
  11.         for (int i = 0; i < rando.length; i++)
  12.         {
  13.             int randomInt = randomGenerator.nextInt(100);
  14.             rando[i] = randomInt;  
  15.             if (i%2 == 0)
  16.             {
  17.                 System.out.println(rando[i]);
  18.             }
  19.            
  20.  
  21.         }
  22.  
  23.     }
  24. }
  25. ---------------------------------------------------------------------------------------------------------------------------------
  26. B)
  27. import java.util.Random;
  28.  
  29.  
  30. public class E1 {
  31.  
  32.     public static void main(String[] args) {
  33.         int[] rando = new int[10];
  34.         Random randomGenerator = new Random();
  35.         int total = 0;
  36.         for (int i = 0; i < rando.length; i++)
  37.         {
  38.             int randomInt = randomGenerator.nextInt(100);
  39.             rando[i] = randomInt;  
  40.             if (randomInt%2 == 0)
  41.             {
  42.                 System.out.println(rando[i]);
  43.             }
  44.            
  45.  
  46.         }
  47.  
  48.     }
  49. }
  50. ---------------------------------------------------------------------------------------------------------------------------------
  51. C)
  52. import java.util.Random;
  53.  
  54.  
  55. public class E1 {
  56.  
  57.     public static void main(String[] args) {
  58.         int[] rando = new int[10];
  59.         Random randomGenerator = new Random();
  60.         int total = 0;
  61.         for (int i = 9; i >= 0; i--)
  62.         {
  63.             int randomInt = randomGenerator.nextInt(100);
  64.             rando[i] = randomInt;  
  65.             if (randomInt%2 == 0)
  66.             {
  67.                 System.out.println(rando[i]);
  68.             }
  69.            
  70.  
  71.         }
  72.  
  73.     }
  74. }
  75. ---------------------------------------------------------------------------------------------------------------------------------
  76. D)
  77. import java.util.Random;
  78.  
  79.  
  80. public class E1 {
  81.  
  82.     public static void main(String[] args) {
  83.         int[] rando = new int[10];
  84.         Random randomGenerator = new Random();
  85.         int total = 0;
  86.         for (int i = 0; i < rando.length; i++)
  87.         {
  88.             int randomInt = randomGenerator.nextInt(100);
  89.             rando[i] = randomInt;  
  90.             if (i == 0)
  91.             {
  92.                 System.out.println(rando[i]);
  93.             }
  94.             if (i == 9)
  95.             {
  96.                 System.out.println(rando[i]);
  97.             }
  98.  
  99.         }
  100.  
  101.     }
  102. }
  103. ---------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement