I have a method that takes in an array (created by Scanner input in main) and sorts the array to find the most common words before printing the length of those words. However, I’m also trying to have an error message pop up if two different elements have the same length; this is where I’m having trouble getting started. Method:
Tag: loops
Java program that asks for user’s name and prints it – issue with error message
I have a program that asks for the user’s name and prints it back out. It can do that part fine, but it currently has the issue of not printing the proper error message when the user leaves the prompt empty and presses “Enter”. The code: The current output: The ideal output: What’s wrong? Answer The only thing that you
I can’t loop my code whenever condition fails. It just prints both blocks of code if the user input is true
I am a beginner at java and I want to loop this all over again but I don’t know how. I’ve tried a while loop but it doesn’t work really well and it prints both blocks of code. What should happen is when I type “quit, Quit, or QUIT”, it should terminate. What happens instead is that it also prints
ArrayIndexOutOfBoundsException when finding words in an array that and with a specific letter
I am trying to find words in an array that end with a letter ‘a’. I thought of doing it using two for loops but I keep getting integer out of bounds error. Could anyone tell me what i am doing wrong? The code: Answer You’ve got too much code for the task, which has lead to a bug creeping
to limit the limit count variable to fixed value
I want to execute some code based on value in limit count, but I want to limit its value to 20000 max. for eg if limit count passed is 50000 then run the code three times with values as 20000,20000,10000 also if limit count is 10000 then run it as is Answer I guess, you need smth like that:
How to call a method and run it asynchronously?
Is there a way to run getUsers() asynchronously only from main() in Java 8? Running getUsers() on the main thread would take 300 seconds. I wish to make it in less than 180 seconds with 4 cores. Without modifying getUsers() (the objective), running the following is still taking 300 seconds: Answer You can divide your loop of users creation into
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.
All array combinations with zero in a loop
The following array is given I now want to loop to output all combinations of these numbers with 0. Each number can occur alone or with any other numbers in the array (the rest should be 0). The original position of the numbers should be maintained when they are included in a combination. The numbers of the original array should
Why do I need to assign -1 to an int for a random number guesser in Java
this is my first question here so I apologize if this has been answered before. I am working through beginner loops in university and am following along my textbook to program a number guesser. The code works, but what I don’t understand is why on line 17 I needed to create an int and give it a value of -1.
Subtraction loops in java
I am new to java and am stuck on this challenge. I am to calculate the state of water depending on the inputed temp and altitude. However, for every 300 metres (for altitude) the boiling point is to drop by 1 degree. I am confused as to how to make it a loop that will take one off for every