while(scanf(“%d“,&n)==1) 在JAVA中实现类似功能

import java.util.Scanner;
public class shujutongji {
    
    

	public final static int INF=1000000000;
	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		int x,n=0,min=INF,max=-INF,s=0;
		Scanner scanner=new Scanner(System.in);
		//次数的#号可以改为其他的标识符
		while(!scanner.hasNext("#")) {
    
    
			x=scanner.nextInt();
			s+=x;		
			if(x<min)min=x;			
			if(x>max)max=x;
			n++;
		}
		System.out.println(min);
		System.out.println(max);
		System.out.println((double)s/n);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_43399648/article/details/107877784