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
Tag: string
Java – Check if user input partialy matches another string?
I have a problem where i want to see if the input user has enterd partially matches, or as long as majority matches with the answer, if it does then it should print out “Almost correct”. For example lets say the answer is Football, but user instead puts in Footbol. It should then print out Almost correct. here is what
Stack in Java not being able to print in specific order
Currently I’m working on a project that is supposed to be a reverse word guessing game. This is how it should work: The use keeps guessing the word until it is fully spelled out. If the user guesses the letter correctly it is revealed if not it is still reveled as shown below ⚠️ Currently I have a stack containing
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.
Adding a String into a scanner
//I wanted to insert a decimal number to console (like 1.85) to the String groesse and I also wanted it to be in the equation of bmi. How do i do that? } Answer How do i do that? OK, so you want to read user input from the console. To do so, instead of … use The same applies
How to simplify String concat in java?
Given the following code: I am trying and discussing in the team how the simpliest code could look like while one could use also constructs like: org.apache.commons.lang3.StringUtils: defaultString() MoreObjects.firstNonNull(user.getVorname(), Strings.EMPTY) A possible test could be like (expected results are visible here too): Any ideas welcome… what could I try? BTW: java 17 is allowed 🙂 The following code seemss to
How to split a string by a newline and a fixed number of tabs like “nt” in Java?
My input string is the following: My intended result is dir, subdir1, subdir2nttfile.ext The requirement is to split the input by “nt” but not “ntt”. A simple try of also splits “tfile.ext” from the last entry. Is there a simple regular expression to solve the problem? Thanks! Answer You can split on a newline and tab, and assert not a
How to remove characters between two specific characters in a String?
How to remove characters between two specific characters in a String? Example: Original String: “Hello <>Remove this String<> how are you?” Modified String: “Hello <><> how are you?” Answer You can use regex like this: Output: Hello <><> how are you?
List of int array in Java
How do I print the contents of a List that contains a primitive type int object in it? Prefer answers to print this in one line. This is the code I have. This will give me [0,1] but I am looking for {[0,1],[2,3]} Answer The following one-liner can meet your requirement: It uses the positive lookbehind and positive lookahead regex
Substring a string in JAVA
Is possible to substring this String = “D:/test/for test/change.txt:D:/test/for test/further.txt:D:/test/for test/yandex.txt” to: Because are two column, I can not split() use “:”. Answer A simple regular expression below splits on “:” that are followed by a “driveletter:” Note that this won’t help if additional paths don’t begin with driveletter: