Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将文件读取器循环成新整数并生成一组新结果?_Java_Loops_Text Files_Filereader - Fatal编程技术网

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);