阅读以下说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
现需要统计某企业员工的月平均工资,即该企业本月发给员工的工资总和除以员工人数。假设企业本月发给员工的工资总和为sumSalary,该企业的员工总数为employeeNumber,下面的程序代码计算该企业员工本月的平均工资,其中需要处理employNumber为0的情况。
【Java 代码】
irnport java.util.Scanner;
pub1ic c1ass JavaMain {
static float average(float x ,int y) throws Exception{
if (y = =0 ) throw new Exception( (1) );
return x/y;
}
static void cacu1ate( ) throws Exception{
float surnSa1ary;
int employeeNumber;
Scanner sc =new Scanner; ( (2) ) ;
try{
System.out.println(" 请输入当月工资总和与员工数: ");
surnSalary=sc.nextFloat( ); //从标准输入获得工资总和
employeeNumber= sc.nextInt ( ) ; //从标准输入获得员工数
float k = average(surnSa1ary ,employeeNumber);
System.out.println(" 平均工资: " + k);
}
(3) (Exception e) {
if (e. getMessage ( ) .equalsIgnoreCase ("zero") ) {
System.out.println(" 请重新输入当月工资总和与员工数: ");
sumSa1ary = sc.nextFloat( );
employeeNumber = sc.nextInt( );
float k = average(surnSa1ary ,employeeNumber);
System.out.println(" 平均工资: " + k);
}
}
}
pub1ic static void main(String[ ] args) {
try {
caculate ( ) ;
}
(4) (Exception e) {
if ( e.getMessage( ) .equalsIgnoreCase(“zero”))
System.out.println(" 程序未正确计算平均工资! " );
}
}
}
【问题 1】
程序运行时,若输入的员工工资总和为6000,员工数为5,则屏幕输出为:
请输入当月工资总和与员工数:
6000 5
(5)
【问题 2】
若程序运行时,第一次输入的员工工资总和为6000,员工数为0,第二次输入的员工工资总和为0,员工数为0,则屏幕输出为:
请输入当月工资总和与员工数:
6000 0
(6)
0 0
(7)