Advertisement
JoshJurban

Exercise 7.1

Nov 20th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package chapter6;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Asdf
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         Random rand = new Random();
  10.         int[] a = new int[10];
  11.        
  12.         // Part A
  13.         for (int i = 0; i < 10; i++)
  14.         {
  15.             a[i] = rand.nextInt(100);
  16.         }
  17.        
  18.         //Part B
  19.         for(int i = 0; i <= 10; i++)
  20.         {
  21.             if (a[i]%2 == 0)
  22.             {
  23.                 System.out.println("Even Element");
  24.                 System.out.println(a[i]);
  25.             }
  26.         }
  27.         //Part C
  28.         for(int i = 0; i <= 10; i++)
  29.         {
  30.             if (i%2 == 0)
  31.             {
  32.                 System.out.println("Element At Even index");
  33.                 System.out.println(a[i]);
  34.             }
  35.         }
  36.         //Part D
  37.         for(int i = 10; i >= 0; i--)
  38.         {
  39.             System.out.print(a[i] + " ");
  40.         }
  41.         for(int i = 0; i <= 10; i++)
  42.         {
  43.             System.out.print(a[10]);
  44.             System.out.print(" ");
  45.             System.out.print(a[0]);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement