Euan Sarson (10W)
8.1 package chapter8;
public class PrimitiveIntegerArray { public static void main (String [] args){ int[] myLuckyNumber = new int[5]; myLuckyNumber[0] = 9; myLuckyNumber[1] = 11; myLuckyNumber[2] = 38; myLuckyNumber[3] = 2; myLuckyNumber[4] = 991; System.out.println(myLuckyNumber[0]); System.out.println(myLuckyNumber[1]); System.out.println(myLuckyNumber[2]); System.out.println(myLuckyNumber[3]); System.out.println(myLuckyNumber[4]);
}
}
8.2 package chapter8; import java.util.Random; import java.util.Scanner;
public class Lottery { public static void main (String [] args){ Scanner scanner = new Scanner(System.in); Random rand = new Random(); int[] number = new int[6]; number[0] = rand.nextInt(54) + 1; number[1] = rand.nextInt(54) + 1; number[2] = rand.nextInt(54) + 1; number[3] = rand.nextInt(54) + 1; number[4] = rand.nextInt(54) + 1; number[5] = rand.nextInt(54) + 1; int[] guess = new int[6]; System.out.println("Hello and welcome to the lottery.\nPlease enter your first number (1-54):"); guess[0] = scanner.nextInt(); System.out.println("Please enter your second number (1-54):"); guess[1] = scanner.nextInt(); System.out.println("Please enter your third number (1-54):"); guess[2] = scanner.nextInt(); System.out.println("Please enter your fourth number (1-54):"); guess[3] = scanner.nextInt(); System.out.println("Please enter your fifth number (1-54):"); guess[4] = scanner.nextInt(); System.out.println("And your Bonus Ball Number please (1-54):"); guess[5] = scanner.nextInt(); System.out.println("---> The winning lottery numbers are:"); System.out.println(number[0]+", "+number[1]+", "+number[2]+", "+number[3]+", "+number[4]); System.out.println("And the bonus ball is: "+number[5]); System.out.println("Would you like to see what you have won? \n[1] Yes\n[2] No"); int iYesorNo = scanner.nextInt();