import java.io.*;
import java.util.Scanner;
public class Q12 {
public static void main(String[] args)
throws FileNotFoundException {
// TODO Auto-generated method stub
Scanner input = new Scanner (new File("/Users/apple/Documents/Class Folders/Java/Lab6/Q12.txt"));
//读取文件
int tem = 0;
int pretem = 0;
int count =0;
while(input.hasNextLine()) {
//拆分
String line = input.nextLine();
Scanner lineScan = new Scanner (line);
while(lineScan.hasNextInt()) {
tem = lineScan.nextInt();
count++;
int difference = tem-pretem;
if (count>1) {
System.out.println("Temperature changes by "+difference+" deg F");
}
pretem=tem;
}
}
//这个实验本身难度很低 只要熟练掌握文件读取的步骤就很简单
}
}
Java逐数读取文件并处理打印"以温度读数实验为例"
最新推荐文章于 2021-03-15 12:00:41 发布