Here's a program that may throw NullPointerException. Fix it to avoid the exception.
In the case when the exception may occur, the program should print the string "NPE!".
NullPointerException
Avoid NPE
Report a typo
Write a program in Java 17
import java.util.*;
class FixingNullPointerException {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
string = "null".equals(string) ? null : string;
/* Do not change code above */
System.out.println(string.toLowerCase());
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.