Home > Back-end >  How to feel not execute catch (InputMismatchException e) code for bosses to see!!!!!!!!!!!!!!!!!!!!!
How to feel not execute catch (InputMismatchException e) code for bosses to see!!!!!!!!!!!!!!!!!!!!!

Time:10-13

 
Import the Java. Util. HashMap;
Import the Java. Util. InputMismatchException;
import java.util.Map;
import java.util.Scanner;

The class Ranking
{
Public static void main (String [] args)
{
String [] teams={" Iran ", "South Korea", "Japan" and "Australia" and "Saudi Arabia", "uzbekistan", "the united Arab emirates, Qatar," Chinese ", "Syria"};
Map map=new HashMap (a);
For (int I=0; i{
The map. The put (I + 1, teams [I]);
}
System. The out. Println (map);
Scanner sc=new Scanner(System.in);
System. Out. Println (" according to input word query the full face one top 10 national men ");
Int number=sc. NextInt ();
Try {
If (number & gt; 0 & amp; & Number & lt;=10)
{
System. The out. Println (" afc ranking the first "+ number +" of the national men's "+ map. Get (number) +" ");
Sc. The close ();
} the else
{
System. Out.println (" input error! One can only enter 1-10 of integer ");
}
} the catch (InputMismatchException e)
{
System. The out. Println (" please enter the number ");
}
}
}

CodePudding user response:

Import the Java. Util. HashMap;
Import the Java. Util. InputMismatchException;
import java.util.Map;
import java.util.Scanner;

The class Ranking
{
Public static void main (String [] args)
{
String [] teams={" Iran ", "South Korea", "Japan" and "Australia" and "Saudi Arabia", "uzbekistan", "the united Arab emirates, Qatar," Chinese ", "Syria"};
Map map=new HashMap (a);
For (int I=0; i{
The map. The put (I + 1, teams [I]);
}
System. The out. Println (map);
Scanner sc=new Scanner(System.in);
System. Out. Println (" according to input word query the full face one top 10 national men ");
Int number=sc. NextInt ();
Try {
If (number & gt; 0 & amp; & Number & lt;=10)
{
System. The out. Println (" afc ranking the first "+ number +" of the national men's "+ map. Get (number) +" ");
Sc. The close ();
} the else
{
System. Out.println (" input error! One can only enter 1-10 of integer ");
}
} the catch (InputMismatchException e)
{
System. The out. Println (" please enter the number ");
}
}
}

CodePudding user response:

InputMismatchException anomaly refers to the values and setting the value of the input types do not match, such as you to set the integer, input the helloworld, the exception will be thrown

CodePudding user response:

CodePudding user response:

The catch is that you try the local anomalies before execution, and you can have a try in the try to write a by zero is unusual, but need to catch in brackets into the Exception e should be followed to see the catch

CodePudding user response:

To put int number=sc. NextInt (); included

CodePudding user response:

The words he would not return to please enter the number???????

CodePudding user response:

refer to 6th floor Lin_bai_ response:
he doesn't return the words please enter the number???????
appear only when you try InputMismatchException this exception will go catch, the catch is you try to capture the exception inside, and you catch in the custom exception superclass for InputMismatchException, so when you try in InputMismatchException or his subclass exception, catch the contents of the output, you are no exception to it captures how to output it? There is no problem of your code execution
  • Related