我需要阅读文本文件以帮助打印到控制台的帮助

问题描述 投票:0回答:1

我无法弄清楚它应该打印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文件的内容,但是我无法打印它。这是即时通讯应该获得的输出。成分__________所需量______ ...

java
1个回答
0
投票

这是我在您的代码中发现的问题:

© www.soinside.com 2019 - 2024. All rights reserved.