# Tag: while-loop

## Throws Exception when trying to break loop because a condition has been met

I am trying to figure out why I cannot get the loop to break if either “n” is input for playAgain or when the total is below \$10. If you see how I can break the loop to run the gameOver function without having an exception thrown that would be a great help. I have noted in the code below

## How can I shorten many while loops?

This is one of my first attempts to use Java and I tried my best, but I need to shorten it so it’s not so long. Important is that it keeps all the coins of the Euro. It’s a German code so geld means money. This part of the code System.out.println(rgeldt + ” mal 2 Euro”); just means how often

## How the output is upto 4 when there is a condition is less than(<)4?

my output is coming along with 4 why } Output: 1 2 3 4 Answer I think the other answer is not exactly explaining the ‘why’. Here is my attempt at that part of the question. Consider the code: We start with counter equal to 0. 0 is less than 4, so we enter the loop body. Here we first

## While loop calculation issue

I’m currently working on a Java program (for school) that prints two statements when a user enters a starting balance for their account. So for example, if the user inputs \$10,000, there will be two statements that print at the same time. One tells them how long it will take for their account to reach \$100,000, and the other when

## Java: How to use a Scanner to check that input is an integer and is within a specified range

I’m having trouble with my code. What it should do: Check if Scanner “myScanner” is an Integer If it is an Integer, if it is between 1 and 200 (both included) Problem: I need to input an Integer with the correct value twice after the the first guess wasn’t correct. Here is a screenshot of exactly what I mean: Screenshot

## How to print number 1 to 10(in that sequence only)using loops(java) if int i = 10

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.

## 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

## why all thing is stop when i’ll use while loop in MouseEntered() Function ?? In Java

My gui programme that contains (JPanel ,JFrame ,JLabel) JLabel : I Coded it To move from (0x, 0y) To (200x ,0y) Pixel by Pixel . it will start when i put the mouse on the panel called “p” ,but when i try to run this programme it’s start correctly ,but when i put my mouse on the panel all thing

## 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

## How to end while loop for integer gathering array in java?

I am wring a program that askes the user to give any value they want as long as it is a whole number, and that value will be placed in a array. They can do this asmany times as they would like, until they add -1 to the array. I am having a hard time figurig out how to get