-1
我無法在此代碼中劃分兩個字符。我需要找到cansNeeded的價值,但我不斷收到一個錯誤無法劃分2個整數
import java.util.Scanner;
import java.lang.Math; // Note: Needed for math functions
public class PaintEstimator {
public static void main(String[] args) {
//Create a new scanner
Scanner scnr = new Scanner(System.in);
//Set the values
double wallHeight = 0.0;
double wallWidth = 0.0;
double wallArea = 0.0;
double gallonsPaintNeeded = 0.0;
final double squareFeetPerGallons = 350.0;
final double gallonsPerCan = 1.0;
//Scan for user input
wallHeight = scnr.nextDouble();
wallHeight = scnr.nextDouble();
wallArea = (wallHeight * wallWidth);
gallonsPaintNeeded = (wallArea/squareFeetPerGallons);
//Print out the values
System.out.println("Enter wall height (feet): ");
System.out.println("Enter wall width (feet): ");
System.out.println("Wall area: square feet");
System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");
double cansNeeded = (gallonsPaintNeeded/gallonsPerCan);
System.out.println("Cans needed: " + cansNeeded + " can(s)");
return;
}
}
我不斷收到此錯誤
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextDouble(Scanner.java:2413)
at PaintEstimator.main(PaintEstimator.java:21)
添加雙似乎解決了我原來的「/」符號的問題引起錯誤。但現在我有下面的錯誤。任何幫助?
你說的是整數和字符,但實際上是使用雙打。你能否試着讓你的問題更清楚(正確)?它會更容易理解 – Stultuske
哪一行是21行? –
看起來像缺少輸入。你輸入了什麼?另外,您的提示在提供輸入後打印。應該可以逆轉。 – Thilo