Question: How do I remove the Exception in thread main java.lang.NumberFormatException: from the main output: Test 1 : failure Expected _ _ _ _ _ _
How do I remove the "Exception in thread "main" java.lang.NumberFormatException:" from the main output:
Test : failure Expected Enter sequence of integers, each followed by a space: Error: Invalid character x found at index in input stream. Received Enter sequence of integers, each followed by a space: Exception in thread "main" java.lang.NumberFormatException: Invalid character x found at index in input stream. at InversionCounter.readArrayFromStdinInversionCounterjava: at InversionCounter.mainInversionCounterjava: Expected length: received length: Test : failure Expected Enter sequence of integers, each followed by a space: Error: Invalid character x found at index in input stream. Received Enter sequence of integers, each followed by a space: Exception in thread "main" java.lang.NumberFormatException: Invalid character x found at index in input stream. at InversionCounter.readArrayFromStdinInversionCounterjava: at InversionCounter.mainInversionCounterjava:
private static int readArrayFromStdin throws IOException,
NumberFormatException
List intList new LinkedList;
BufferedReader reader new BufferedReader
new InputStreamReaderSystemin;
int value index ch;
boolean valueFound false;
while ch reader.read
if ch && ch
valueFound true;
value value ch ;
else if ch ch
ch r
if valueFound
intList.addvalue;
value ;
valueFound false;
if ch
break;
else
throw new NumberFormatException
"Invalid character charch
found at index index in input stream.";
index;
int array new intintListsize;
Iterator iterator intList.iterator;
index ;
while iteratorhasNext
arrayindex iterator.next;
return array;
public static void mainString args throws IOException, NumberFormatException
if argslength
System.out.printlnUsage: java InversionCounter slow;
System.exit;
if argslength && argsequalsslow
System.out.printlnError: Unrecognized option args;
System.exit;
System.out.printEnter sequence of integers, each followed by a space: ;
int array readArrayFromStdin;;
if arraylength
System.out.printlnError: Sequence of integers not received.";
System.exit;
if argslength && argsequalsslow
System.out.printlnNumber of inversions: countInversionsSlowarray;
else
System.out.printlnNumber of inversions: countInversionsFastarray;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
