Question: Java Exception Write an application that asks the user to Enter two integers separated by a comma. You will need to use a String data
Java Exception
Write an application that asks the user to "Enter two integers separated by a comma". You will need to use a String data type to get this input. The String class has a method name split( ) that takes a String and converts it to an array of type String based on a separator that you provide as the argument to the split( ) method.
For example:
String xStr = "6-3-2";
String vals[];
vals = xStr.split("-");
for( int i = 0; i < vals.length; i++)
System.out.print( vals[i] + " ");
The output would be: 6 3 2
Do the following error checking. Some of the error checking may use try/catch and some of it may be done using if statements.
1. Display an error if the user entered fewer than 2 values.
2. Display an error if the user entered more than 2 values.
3. Display an error if either value cannot be converted to an integer.
You should not let the user continue until they have entered two valid values that can be converted. Save the file as SplitInput.java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
