我无法弄清楚它应该打印txt文件的内容,但是我无法打印它。
这是我应该得到的输出。
成分______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________水中库存物中的的的含量的多少。
小苏打_________ 4.50 ________________ 4.00
糖______________ 6.50 ________________ 3.20
import java.util.Scanner;
import java.lang.*;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
public class Lab8b {
public static void main(String[] args) throws FileNotFoundException {
Scanner scan = new Scanner(System.in);
System.out.print("Enter file name : ");
String filename = scan.nextLine();
Scanner fileScan = new Scanner(new File(filename));
while (fileScan.hasNext()) {
String name = fileScan.nextLine();
String ingredientName = fileScan.nextLine();
double amountNeeded = Double.parseDouble(fileScan.nextLine());
double amountInStock = Double.parseDouble(fileScan.nextLine());
if (amountNeeded > amountInStock) {
System.out.printf("Ingredient \t Amount Needed \t Amount in Stock");
System.out.println();
System.out.printf("%10s", ingredientName);
System.out.printf("%8.2f", amountNeeded);
System.out.printf("%16.2f", amountInStock);
} //end if
if (amountNeeded <= amountInStock) {
System.out.println("Nothing");
} //end while
} //end if
} //end main
} //end class
我无法弄清楚它应该打印txt文件的内容,但是我无法打印它。这是即时通讯应该获得的输出。成分__________所需量______ ...
这是我在您的代码中发现的问题: