我需要帮助从文本文件中读取数据并根据用户输入提供输出。
以下是我在“data.txt”文件
下保存在记事本中的数据C|C,370,0.154 C||C,680,0.13 C|||C,890,0.12 C|H,435,0.11 C|N,305,0.15 C|O,360,0.14 C|F,450,0.14 C|Cl,340,0.18 O|H,500,0.10 O|O,220,0.15 O|Si,375,0.16 N|H,430,0.10 N|O,250,0.12 F|F,160,0.14 H|H,435,0.074
这就是我在记事本中的数据。是的,每个条目用逗号分隔
我知道基本的阅读操作Scanner
类读取行并从每行中吐出文本,但这次我输入的是债券数或债券长度,它给出了剩余两个值的输出。
分配:
不,我不是要求你做作业,而是帮助我学习这个过程。
import java.io.*;
import java.io.FileNotFoundException;
import java.util.*;
public class LearnReadText
{
public static void main (String args[]) throws FileNotFoundException
{
Scanner input = new Scanner(System.in);
String strResponse="";
do
{
System.out.println("\nChapter 7");
System.out.println("L - Bond Length");
System.out.println("N - Bond Numbers (1=single, 2=double, 3=triple)\n");
System.out.println("Q - quit program.");
strResponse = input.nextLine();
strResponse = strResponse.toUpperCase();
Scanner file = new Scanner(new File("data.txt"));
file.close();
}
while (!strResponse.equals("Q"));
System.out.println("\n\nThank you and have a nice day.");
input.close();
}
}