testsetinput.java

来自「由浅入深的介绍JAVAse的基本编程思想」· Java 代码 · 共 27 行

JAVA
27
字号
import java.io.*;

public class TestSetInput{
	public static void main(String[] args){
		try{
			//FileInputStream fis = new FileInputStream("source.txt");
			//System.setIn(fis);			
			int avg = 0;
			int total = 0;
			int count = 0;
			int num = 0;
			int i;
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String s = br.readLine();
			while(s != null && !s.equals("over")){
				i = Integer.parseInt(s);
				num++;
				total += i;
				avg = total/num;
				System.out.println("num=" + num + "\ttotal=" + total + "\tavg=" + avg);	
				s = br.readLine();
			}
		}catch(Exception e){
			e.printStackTrace();	
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?