Answer:
import java.util.Random;
class Main {
public int stopAtFive (int j) {
Random rand = new Random();
int number = 0;
for(int i=0; i<j; i++) {
number = rand.nextInt(9)+1;
System.out.println(number);
if (number == 5) {
System.out.println();
break;
}
}
return number;
}
public static void main(String args[]) {
Main main = new Main();
main.stopAtFive(20);
main.stopAtFive(20);
}
}
Step-by-step explanation:
Your requirements do not say what has to be displayed or returned from the method, but you can use this as a starting point.