我不斷收到此錯誤消息,我無法弄清楚發生了什麼。我不斷收到錯誤消息「線程中的異常」main「java.util.NoSuchElementException」,然後說我的掃描器有一個未知的源。Java中的未知源代碼Eclipse
任何想法發生了什麼?
package pizza;
import java.util.Scanner;
public class Pizza {
public static void main(String[] args) {
Double diameter;
Double radius;
Double cost;
Double area;
final Double costPerInch;
//Ask and enter diameter
System.out.println("What is the diameter?");
Scanner size = new Scanner(System.in);
diameter = size.nextDouble();
size.close();
radius = diameter/2;
//Ask and enter price
System.out.println("What is the price of the pizza?");
Scanner price = new Scanner(System.in);
cost = price.nextDouble();
price.close();
//Calculate cost per inch
area = radius * Math.PI;
costPerInch = cost/area;
//Output results
System.out.println("The cost per inch of the pizza is" + costPerInch);
我編譯了這個罰款。當我嘗試輸入內容時會出現錯誤。它不喜歡直接使用的double。除此之外,你應該沒問題。 – durbnpoisn
你爲什麼要關閉並重新創建掃描儀? –