没有输入值时,编译器不执行该catch
部分:
import java.util.Scanner;
import java.lang.*;
public class Ruff {
public static void main(String[] args)
{
String a;
Scanner scanf=new Scanner(System.in);
System.out.println("Enter your name!!");
a=scanf.nextLine();
try
{
if(a.toLowerCase().equals("Harsh"))
{
System.out.print("Good Name");
}
else
{
System.out.print("Ok!");
}
}
catch(Exception e)
{
System.out.print("Name Required");
}
}
}