Skip to content
Advertisement

Tag: if-statement

If else condition with StringBuffer

I’m trying to make a If else condition to check if a current data exists on the database using a JSON request on a java application consuming a Rest Webservice. So, I want to receive a boolean or make a condition to verify what i’m receiving (normally, null or true/false) There’s a way to transform this in a boolean to

how to make code print Suspended instead of won

Code doesn’t output Suspended but outputs Won when the user inputs true. Can someone help explain what have I done wrong with this code, please? Answer You use = incorrectly. In your example, if(isSuspended = true) {} means: To not assigned but check, you should use == instead. or better: P.S. I think you also mixed up the if cases.

Finding the longest word ArrayList /Java

I want to write a method which finds the longest String (word). The output should be the longest word in case of two words with the same lenght the output should be: “More than one longest word”. I used ArrayList and almost had a solution, but something goes wrong. The case is that I have a problem when two words

Implementing a printAnimals method

I am trying to implement a printAnimals() method that prints the ArrayList for dogs or prints the ArrayList for monkeys, or prints all animals whose training status is “in service” and whose is Not reserved, depending on the input you enter in the menu. I am trying to correctly write a for loop for both ArrayList that contains if statements,

Switch Case In ActionPerformed?

Ive gone through some stack overflow questions and found this similar question. From what I understand using a switch statement in an actionPerformed method for this context will not work and an if-else statement is required. Is there a more efficient way to do this without having repetitive code? I’ve heard I could use Abstract Action to give multiple buttons

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

Advertisement