Westonci.ca is the premier destination for reliable answers to your questions, provided by a community of experts. Join our platform to connect with experts ready to provide precise answers to your questions in various areas. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields 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:
Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Westonci.ca is your go-to source for reliable answers. Return soon for more expert insights.