Why does for each scan in each if{}, it prints out everything and doesn't print out wait for input and then print out the next and wait for input?
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
//ask if the user wants to encode or decode
System.out.println("Type the number 1 if you want to encode OR type the number 2 to decode: ");
int Option1 = scan.nextInt();
if (Option1 == 1)
{
//encode
System.out.println("Enter the text to encode: ");
String EncodeText1 = scan.nextLine();
//why does this skip and not wait for the first scan input?
//shift amount
System.out.println("Enter the shift value to encode: ");
int EncodeShift1 = scan.nextInt();
//printing out the final result
//n/a for example
}
else if (Option1 == 2)
{
//decode
System.out.println("Enter the text to the decode: ");
String DecodeText1 = scan.nextLine();
//same to here
//shift amount
System.out.println("Enter the amount to be shifted: ");
int DecodeShift1 = scan.nextInt();
//printing out the final decoded text
//n/a for example
}
}
}
What can I add to make this not happen?
Type the number 1 if you want to encode OR type the number 2 to decode:
1
Enter the text to encode:
Enter the shift value to encode:
it doesn't wait for input it just prints everything out