Explore Westonci.ca, the leading Q&A site where experts provide accurate and helpful answers to all your questions. Connect with a community of experts ready to help you find solutions to your questions quickly and accurately. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.
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 on our site. Don't hesitate to return whenever you have more questions or need further clarification. We hope our answers were useful. Return anytime for more information and answers to any other questions you have. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.