Hello, I'm fairly new to java and I need some help with my first program. I'm trying to make a program in which the user makes bet that he will roll a certain number on a die. But I am having trouble trying to test the input i receive. I need to see if the bet entered is a integer, if its not then they need to renter the bet. I am used to GoTo statements used in Visual Basic but I'm not sure how to accomplish this affect in java. Help is appreciated.
Code:
import java.util.Random;
import java.io.*;
package dicegame;
public class Main {
@SuppressWarnings("empty-statement")
public static void main(String[] args) throws IOException {
Random generator = new Random();
int rnNum;
int betInput = 0;
rnNum = generator.nextInt(6) +1;
System.out.println("Welcome to the dice betting game. Please enter a bet: ");
while ((betInput = System.in.read()) != '\n');
TEST:
if (betInput >= '0' && betInput <= '6') {
System.out.println("Success");
break TEST;
} else {
System.out.println("Your bet was not valid. Please re-enter your bet: ");
betInput = System.in.read();
}
}
}
Comment