Skip to content
Advertisement

Tag: loops

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

Asynchronous execution/operation with CompletableFuture in Java 8+

In Java, is calling get() method while looping on CompletableFuture instances as good as doing synchronous operations although CompletableFuture is used for async calls? Answer ‘get()’ waits until the future is completed. If that’s what you want, it’s what you use. There’s no general rule. For example, you might be using a method that is inherently asynchronous, but in your

Java Contain method cannot find symbol

I am trying to only print strings containing the word “The” from a text file but the contain method does not seem to be working. Is there any other way to do this or fix the contain method? } Answer You’re calling contains on Scanner object, you should call it on the lines that you read from file, that’s the

Is there a way to go back by one iteration in a for-each loop?

For example, if I were to do… If it isn’t possible, is there another method of traversing through some sort of collection class while controlling the iteration counter? I tried looking through the answers to this question but couldn’t think of a way that was clear to me. Any suggestions are appreciated! Answer It depends on what you are trying

Return a value present from recursive function in Java

I am trying to extract a value from a while loop. In the output, I am able to capture the value in the Else statement but not able to return it when it is in the console log from the main statement. I want to be able to return “103” when I call the getValueFromkey() function. Sample XML Output: From

Advertisement