好的 - 所以这是一个非常简单的java程序。我一直收到以下错误。阅读完文档后,我确保所有扫描程序语句都已正确编码。我做错了什么?
Enter working hours: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at WeeklyWages.main(WeeklyWages.java:12)
以下是代码:
import java.util.*;
public class WeeklyWages {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
double hrsworked, payrate, wages;
System.out.print("Enter working hours: ");
hrsworked = console.nextDouble();
System.out.println();
System.out.print("Enter the payrate: ");
payrate = console.nextDouble();
System.out.println();
if (hrsworked > 40)
wages = 40.0 * payrate + 1.5 * payrate * (hrsworked - 40.0);
else
wages = hrsworked * payrate;
System.out.printf("Hours worked = .2%f %n", wages);
System.out.println();
}
}
答案 0 :(得分:0)
Ok看起来像Sublimetext有问题。我只是通过dos中的javac编译它,它工作。奇怪的。
答案 1 :(得分:0)
我认为你的语法错误,并没有导入库“java.util.scanner”
这是适合你的代码
import java.util.Scanner;
公共类MainPrintThread {
public static void main(String args[])
{
Scanner console = new Scanner(System.in);
double hrsworked, payrate, wages;
System.out.print("Enter working hours: ");
hrsworked = console.nextDouble();
System.out.println();
System.out.print("Enter the payrate: ");
payrate = console.nextDouble();
System.out.println();
if (hrsworked > 40)
wages = 40.0 * payrate + 1.5 * payrate * (hrsworked - 40.0);
else
wages = hrsworked * payrate;
System.out.printf("Hours worked = .2%f %n", wages);
System.out.println();
}
}