JAVA · ОСНОВЫ · LESSON 24
If the input breaks
try and catch · about 17 minutes
Learning with progressRead the summary for free. To save the work, log in to the account.
Type the code yourself
Type an example manually. Check the signs and brackets.
public class Main {
public static void main(String[] args) {
try {
int number = Integer.parseInt("кот");
System.out.println(number);
} catch (NumberFormatException error) {
System.out.println("Нужно число");
}
}
}Open the editor for class workSolve it yourself
In try, try turning a string of «abc» into int using Integer.parseInt and output a number. In catch for NumberFormatException, output «Введи число».
The answer is hidden. Use similar examples from the lesson notes.
Opening up your homework