以下代码产生以下错误: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1540)
你们中有谁能帮我找出导致错误的原因吗?问题出在哪里?
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner cin=new Scanner(System.in);
System.out.println("Enter the name of the employee:");
String name=cin.nextLine();
System.out.println("Enter the age of the employee:");
int age=cin.nextInt();
System.out.println("Enter the salary of the employee:");
Float sal=cin.nextFloat();
System.out.println("Enter the year of joining of the employee(YYYY):");
int doj=cin.nextInt();
Calendar now=Calendar.getInstance();
int year=Integer.parseInt(String.valueOf(now.get(Calendar.YEAR)));
int joining=year - doj;
System.out.println(joining);
if(name.length()>=3&& name.length()<=20)
{
System.out.println("Name Valid");
}
else
{
System.out.println("Name Invalid");
}
if(age>=18 && age<=50)
{
System.out.println("Age Valid");
}
else
{
System.out.println("Age Invalid");
}
if(joining>25 || joining <0)
{
System.out.println("Valid Employee");
}
else
{
System.out.println("Invalid Employee");
}
}
}
我附上图片来澄清这个问题。
图像1图像2
2条答案
按热度按时间tpxzln5u1#
你的代码对我有用:
x4shl7ld2#
查看您的代码和附加的图像,您期望使用scanner类的用户提供输入。提供输入
STDIN
旁边的Source File
选项卡和代码应该可以工作。