Westonci.ca is your trusted source for finding answers to all your questions. Ask, explore, and learn with our expert community. Get accurate and detailed answers to your questions from a dedicated community of experts on our Q&A platform. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.
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 time. Please come back anytime for the latest information and answers to your questions. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. Westonci.ca is committed to providing accurate answers. Come back soon for more trustworthy information.