Java 将文件读取器循环成新整数并生成一组新结果?
基本上,我想从文本文件中读取一些数据,将它们放入多个整数中,然后进行一些计算。然后循环扫描仪再次执行所有操作 这是我目前掌握的代码。用户将输入建议的金额,系统应能够计算船舶成本Java 将文件读取器循环成新整数并生成一组新结果?,java,loops,text-files,filereader,Java,Loops,Text Files,Filereader,基本上,我想从文本文件中读取一些数据,将它们放入多个整数中,然后进行一些计算。然后循环扫描仪再次执行所有操作 这是我目前掌握的代码。用户将输入建议的金额,系统应能够计算船舶成本 int RM; System.out.print("Enter the Recommened Journey cost: "); RM = user_input.nextInt(); Scanner inFile = new Scanner(new FileReader(task3.txt)); int shipI
int RM;
System.out.print("Enter the Recommened Journey cost: ");
RM = user_input.nextInt();
Scanner inFile = new Scanner(new FileReader(task3.txt));
int shipID = inFile.nextInt();
int journeyID = inFile.nextInt();
int length = inFile.nextInt();
int numberOfCrew = inFile.nextInt();
int hourlyRate = inFile.nextInt();
int shipCost = hourlyRate*length*numberOfCrew;
if(shipCost<=RM)
{
System.out.println("The ship is below the Recommeneded journey cost");
}
else if(shipCost>=RM)
{
System.out.println("The ship is over the Recommeneded journey cost");
}
有人能帮我吗 我认为您正在寻找获取名为task3.txt的
文件的方法。假设您希望该文件位于用户的主目录中,您可以使用
File f = new File(System.getProperty("user.home"), "task3.txt");
Scanner inFile = new Scanner(f);
注意:将从给定的文件
生成值
此外,建议的文件布局从非int
的内容开始。你需要阅读这些/还没有解释它们
File f = new File(System.getProperty("user.home"), "task3.txt");
Scanner inFile = new Scanner(f);