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
Tag: loops
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
Regex for letters and numbers with any underscores in between
I’m trying to create a Regex String with the following rules The username is between 4 and 25 characters. It must start with a letter. It can only contain letters, numbers, and the underscore character. It cannot end with an underscore character. when it meets this criterion I want the output to be true otherwise false, but I only get
Reading a file and saving each line into a variable
For a project of mine, I’m trying to read a file of Integers and save each line into a file. Each of the files I’m reading have a different amount of lines. The file would look like 17 72 61 11 63 95 100 Is there a way I can use a loop and save the value in a different
Retrieve all queue data in for loop
I have the following code which works fine but I am struggling to figure out how to retrieve the last value in the queue. Here is the output: Answer Since you’re incrementing x and decreasing the size of the queue, x will eventually become bigger than the remaining queue size before the queue is empty. You can change your loop
Trying to stop a Do-While Loop for an application
I’m creating an application for a homework, the problem is that I am trying to create a do-while loop to exit the application (Using the question “Do you want to exit (Y/N)”). To work with the do-while loop, I created a method to store the app and then called the method in the do-while loop, so that when I try
How to set the Thread priority on parallel iteration with standard Java API?
I found in this tutorial a way to iterate in parallel a collection of objects by setting threads priority, but this example uses the Burningwave Core library: is there a way to do the same with the standard Java API? I found in this tutorial a way to iterate in parallel a collection of objects by setting threads priority, but
How can I loop through a linked list and print each piece of data that matches the input?
I’m working on this method but am running into an issue. When I enter a word that matches the data in an index of the linked list, it only prints the first index of the Linked List the same number of times that the word I entered appears in the entire linked list. For example: The linked list contains these
Nested for-loop problem with descending number
I’m trying to figure out how to complete this problem. I’m shooting for: and I have the following code, which gives me this: I think I’m close but can some one help? } Answer I think the problem is with the logic you used. I made an algorithm inspired by another idea, maybe it will help you. I am sure
How to reduce/iterate multiple java streams of same size at once?
I have multiple Java streams of the same length, and I want to perform some operation on the corresponding elements of each stream. For e.g., add 1st elements of all stream, 2nd elements of all streams and 3rd elements of all streams and so on. How can we do this without first reducing each of the streams? for Minimum reproducible