Exception in thread “main” java.util.NoSuchElementException

You close the second Scanner which closes the underlying InputStream, therefore the first Scanner can no longer read from the same InputStream and a NoSuchElementException results. The solution: For console apps, use a single Scanner to read from System.in. Aside: As stated already, be aware that Scanner#nextInt does not consume newline characters. Ensure that these are consumed before attempting to call nextLine again by using Scanner#newLine(). See: Do not create multiple buffered wrappers on … Read more

What does “Could not find or load main class” mean?

The java <class-name> command syntax First of all, you need to understand the correct way to launch a program using the java (or javaw) command. The normal syntax1 is this: where <option> is a command line option (starting with a “-” character), <class-name> is a fully qualified Java class name, and <arg> is an arbitrary … Read more

Java String Split by “|”

ou must use: This is because the split method takes a regular expression, and | is one of the special characters. It means ‘or’. That means you are splitting by ” or ”, which is just ”. Therefore it will split between every character. You need two slashes because the first one is for escaping the actual \ in the string, since \ is Java’s escape … Read more

Reverse a string in Java

You can use this: Or, for versions earlier than JDK 1.5, use java.util.StringBuffer instead of StringBuilder — they have the same API. Thanks commentators for pointing out that StringBuilder is preferred nowadays when there is no concurrency concern.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)