一:
import java.util.Scanner;
public class www{
pubilic static void main(String [] args){
int a=0;
int sum=0;;
int num=0;
int=t;
while(a!=-1){
System.out println("请输入员工工资:")
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
sum+=a;
num++;
}
sum=sum+1;
num=num-1;
t=sum/num;
System.out.println("员工的平均工资:"+t);
}
}
二:
import Java.util.Scanner;
public class ww{
public static void main (String [] args){
int a=0;
int sum=0;
int num=0;
float t;
do{
System.out.println("请输入工资:");
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
sum+=a;
num++;
}while(a!=-1);
sum=sum+1;
num=num-1;
t=sum/num;
System.out.println("平均工资为:"+t);
}
}
两种方法运行结果: