IDNLearn.com makes it easy to find accurate answers to your specific questions. Receive prompt and accurate responses to your questions from our community of knowledgeable professionals ready to assist you at any time.
Sagot :
Explanation:
Your problem arises in the user input. When taking a user input, and using the input() function, you need to ask the user something:
Instead of:
miles_per_gallon = float(input())
You need to enter text in the form:
miles_per_gallon = float(input("Enter a value: "))
This may be the format in which you included your code but remember, indentation is important so lines 3, 9, and 12 need to be indented.
Hope this helps!
Answer:Change your logic to:
for (int i = 0; i < 4; i++) {
System.out.println("Please input a number between zero to 3");
// use input and don't advance the scanner every time
int input = sc.nextInt();
if (input == 0) {
System.out.println("You have selected " + right);
}
if (input == 1) {
System.out.println("You have selected " + left);
}
// so on and so forth
}
By using sc.nextInt() four times, you are looking for the next token of the input which isn't there. So fetch the input for each run of the for-loop and it will work as expected.
Explanation:
We appreciate your participation in this forum. Keep exploring, asking questions, and sharing your insights with the community. Together, we can find the best solutions. Accurate answers are just a click away at IDNLearn.com. Thanks for stopping by, and come back for more reliable solutions.