Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in Java, is there a way to take the results of what I get here prior to printing to screen by using a separate method
in Java, is there a way to take the results of what I get here prior to printing to screen by using a separate method to store them into an array that checks for duplicates (making sure there are no duplicates for the 5 random numbers) before printing it to out to the user? I'm supposed to use an enhanced for loop to print the array elements.
public static void lottopicks(int[]numpassed) { Scanner read = new Scanner(System.in); Random rand = new Random(); int num; int min = 1; int max; int num1; int min1=1; int max1=40; { while (true) { System.out.println("What is the upper range of values you want to use for Random numbers): " + "valid value is between 23 and 100 (e.g, enter 54 to generate numbers between 1 and 54)"); max = read.nextInt(); if(max >= 23 && max <= 100) { break; } System.out.println("Please enter a valid range. "); } System.out.println("The Easy Pick Randomly Generated Numbers Are:"); for (int i = 0; i <= 4; i++) { num = rand.nextInt((max + 1) - min) + min; System.out.print(num + " "); numpassed[i]=num; } for (int j=0; j<=0; j++) { num1 = rand.nextInt((max1 + 1) - min1) + min1; System.out.print("Powerball is " + num1); } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started