I need to write an input validation while using the do-while statement. I feel like most of it is good except that it gets stuck inside the brackets of the do statement. After I enter an input, it just keeps asking me over and over for an input. Any help?
Then I have to make it s if you enter an input that is out of range, you have to keep entering an input until it is in range.
Java Code:
do
{
System.out.print("Please enter the amount of spaces the letters will shift... ");
shift = uInput.nextInt();
}
Java Code:
public class ShiftEncoderDecoderDriver
{
public static void main(String[] args)
{
int shift;
Scanner uInput = new Scanner(System.in);
System.out.print("Please enter the code that you wish to encode...");
String plainText = uInput.nextLine();
{
do
{
System.out.print("Please enter the amount of spaces the letters will shift... ");
shift = uInput.nextInt();
}
while(shift > 0 || shift < 25);
{
System.out.print("Your shift value is set at... "+shift);
}
while(shift > 0 || shift > -25);
{
System.out.print("Your shift value is set at... "+shift);
}
while(shift > 25 && shift < -25)
{
System.out.print("Out of range shift amount, please enter your shift amount again.");
shift = uInput.nextInt();
}
}
}
No comments:
Post a Comment