Java逐数读取文件并处理打印"以温度读数实验为例"

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Hollen0318/article/details/102763996

读数实验

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;
		}
		}
	
//这个实验本身难度很低 只要熟练掌握文件读取的步骤就很简单
	}

}

猜你喜欢

转载自blog.csdn.net/Hollen0318/article/details/102763996
今日推荐