Output must be 1 2 3 4 5 6 7 8 9 10 I have tried While loop but it prints from 10 to 1 Answer Assuming you must use i with an initial value of 10.
Tag: while-loop
Nested While loop not counting two files correctly
I am working on a program that takes a file in from the command line. this file is then compared to a text file to see if it has certain words in it. if it does, i want it to increment a counter for each time that certain word is found. I thought I was on the right track, using
how do I break a while loop when asking for user input?
i need to try to break the while loop when a user enters an empty line instead of countries. Here is the code I have done so far and it does not seem to want to end the loop of asking for countries: the user input should look as follows: Answer Your checking for hasNext() but should be checking for
stringRounds is Looping, Rejecting Valid Value
The loop is working when I enter invalid values, but it still shows the same message when I enter a Valid value. Please help. Answer Because you don’t update the value of rounds in the while loop.
How to properly use this while loop within my method to have user retry input to a maximum of three times
Hi I am creating a mock atm, and I created a method to check if the user’s pin is inputted wrong, but if it is wrong it spams incorrect pin 3 times then my program stops, I am looking at how to have the user input incorrectly have it tell them it is wrong once then have them retry their
How to find max number and occurrences
So I’m learn java for the first time and can’t seem to figure how to set up a while loop properly . my assignment is Write a program that reads integers, finds the largest of them, and counts its occurrences. But I have 2 problems and some handicaps. I’m not allowed to use an array or list because we haven’t
Tic Tac Toe runs and functions completely, but after getting 3 in a row, another move has to be made for it to end [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago. Improve this question Is anyone of you able to find out why it loops around 1 extra time even though the while condition
While loop keeps executing a command after a break statement
I’m doing the University of Helsinki Java MOOC and there’s an exercise that consists in creating a program that lets you input as much numbers as you want, but as soon as you input a 0 the program ends and prints the total number of inputs you did and the sum of all of them. I wrote the code and
Can I run a while loop inside a for loop? [Java] If so, how would I do it in this scenario?
Im doing some simple maths using loops and my task is as follows: “Given an integer,N , print its first 10 multiples. Each multiple N * i (where 1 <= N <= ) should be printed on a new line in the form: N x i = result.” My input has to be : My output: Sample Input: Sample Output:
I have a while loop and I want to call the variable multiple times is it possible?
An example of this would be i = 0; while(i < 3) { Scanner scan = new Scanner(); String variableIWantToCallLater = scan.nextLine(); } User enters macaroni the first time sausage the second time and …