java programming Your assignment in problem 1 is to write a Java program that le
ID: 3876084 • Letter: J
Question
java programming
Your assignment in problem 1 is to write a Java program that lets you select six lottery numbers. To simplify this first version, you can accept any six values including duplicates. Your program must have the following elements: Create a class named Lottery1 .Use a loop to continue prompting for the six integers. Exit when all six values have been captured. Use an array to store the six int values. After populating the array, use a loop to print out each of the values. .Perform everything within the main method. SAMPLE OUTPUT: java Lottery1 Enter a number from 1-54 (pick #1): 12 Enter a number from 1-54 (pick #2): 60 Enter a number from 1-54 (pick #3): 12 Enter a number from 1-54 (pick #4): 26 Enter a number from 1-54 (pick #5): 15 Enter a number from 1-54 (pick #6): 9 Playing the following six numbers: 12 60 12 26159Explanation / Answer
import java.io.*;
public class Lottery1
{
public static void main(String args[])throws IOException//Main Method
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));//BufferClass
//Array Declaration of length 6
int arr[]=new int[6];
//Array Populating
for(int i=0;i<6;i++)// For loop with 6 repeatations
{
System.out.print(" Enter a number from 1-54 (pick #"+(i+1)+"): "); // Accepting 6 numbers
arr[i]=Integer.parseInt(br.readLine()); //Storing 6 numbers in array
}
//Displaying Required Output
System.out.println(" Playing the following six numbers: ");
for(int i=0; i<6; i++)// For loop with 6 repeatations
{
System.out.print(arr[i]);//Displaying Array Elements
}
}
}
Note: Executed in BlueJ
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.