hello, i have some questions that i am stuck on in programing class. we are supposed to answeers 3 questions about the flowing loto program.
import java.util.Scanner;
import java.io.*;
public class Loto2 {
public static void main (String [] args) throws IOException {
File f = new File ("LotoGrid.txt");
FileWriter fw = new FileWriter (f);
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter pw = new PrintWriter (bw);
Scanner scan = new Scanner (System.in);
int[] choice = new int[6];
int temp;
for (int i = 0; i <= 5; i++) {
for (int j = 7*i + 1; j <= 7*(i+1); j++) {
switch(j/10) {
case 0:
pw.print(" " + j + " ");
break;
default:
pw.print(j + " ");
}
}
pw.println();
}
System.out.println();
System.out.println("Enter your choice of 6 numbers:");
for (int i = 0; i <= 5; i++) {
temp = scan.nextInt();
if (temp <= 0 || temp > 42) {
System.out.println("Invalid number! Re-enter!");
i--;
}
else
choice[i] = temp;
}
pw.close();
}
}
the questions are :
1) modfiy the floowung piece of code where we wants this code
(int i = 0; i <= 5; i++) {
temp = scan.nextInt();
if (temp <= 0 || temp > 42) {
System.out.println("Invalid number! Re-enter!");
i--;
to look like this
(int i = 0; i <= 5[b];[(temp <= 0 || temp > 42)][/b] i++) {
temp = scan.nextInt();
System.out.println("Invalid number! Re-enter!");
i--;
2) modify the flowing piece of code to in such a way to account for same condition without suing IF statement
for (int i = 0; i <= 5; i++) {
temp = scan.nextInt();
if (temp <= 0 || temp > 42) {
System.out.println("Invalid number! Re-enter!");
i--;
}
else
choice[i] = temp;
}
pw.close();
3) print the loto grid using one for loop i.e:
for (___,___,___)
system.out println("");