第1题
【说明】
Java.util包中提供了HashMap模板类,该模板类可以表示多个“键一值”对的集合,其中“键”的作用与普通数组中的索引相当,而“值”用作待存储和检索的数据。HashMap实现了Map接口。在Map接口中定义了put和get方法,put方法表示Map对象中加入一个“键-值”对,get方法则通过“键”来获取其对应的“值”。
下面的Java代码中使用了HashMap模板类,将编号为1001、1002、1003的员工信息插入到HashMap对象中,然后输入一个指定的员工编号,通过员工编号来获取员工的基本信息。员工编号为整型编码,而员工的基本信息定义为类employee。HashMap对象与员工对象之间的关系及存储结构如图5—2所示。
【Java代码】
import Java.util.*;
class employee{
employee(String name,String phoneNumber,String address){
this.name=name;
thi s.phoneNumber=phoneNumber ;
this.address=address;
}
String name;
String phoneNumber;
String address;
};
publ ic class jaVaMain{
public static void main(String[]args){
MapemployeeMap=new HashMap(Integer,employee>();
for(Integer employIndex=1001;employIndex<=1003;employIndex++){
String tmp=employlndex. (1 ) ();
employeeMap. (2) (employIndex, (3) (”employee-”+
tmp,“85523927-”
+tmp,”addresS-”
+tmp)
);//将员工编号和员工信息插入到employeeMap对
象中
)
int employeeNo=0;
System.out.print(”请输入员工编号:”);
Scanner S=new Scanner(System.in);
employeeNo=.s.nextInt(); //从标准输入获得员工编号
employee result=employeeMap. (4)(employeeNo);
if( (5) ==null)(
System.out.println(”该员工编号不存在!”);
return;
System.out.println(“你所查询的员工编号为:”+employeeNo);
System.out.printld(“该员工姓名:”+result.name);
System.out.println(“该员工电话:”+result.phoneNumber);
System.out.println(“该员工地址:“+result.address);
}
}
第2题
[说明]
现需要统计某企业员工的月平均工资,即该企业本月发给员工的工资总和除以员工人数。假设企业本月发给员工的工资总和为sumSalary,该企业的员工总数为employeeNumber,下面的程序代码计算该企业员工本月的平均工资,其中需要处理employNumber为0的情况。
[Java代码]
import Java.util.Scanner;
public class JavaMain{
static float average(float X,int Y)throws Exception{
if(Y==0)throw new Exception( (1)______ );
return X/Y;
}
Static Void caculate()throws Exception{
float sumSalary;
int employeeNumber;
Scanner SC=new Scanner( (2)______);
try{
System.out.println("请输入当月工资总和与员工数:");
sumSalary=sc.nextFloat(); //从标准输入获得工资总和
employeeNumber=SC.nextInt(); //从标准输入获得员工数
float k=average(sumSalary,employeeNumber);
System.out.println("平均工资:"+k);
}
(3)______ (Exception e){
if(e.getMeSSage().equalSIgnoreCase("zero")){
System.out.println("请重新输入当月工资总和与员工数:");
sumSalary=sc.nextFloat();
employeeNumber=sc.nextInt();
float k=average(sumSalary,employeeNumber);
System.out.println("平均工资:"+k);
}
}
}
public Static void msin(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)______
第3题
阅读以下说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【 说明 】
现需要统计某企业员工的月平均工资,即该企业本月发给员工的工资总和除以员工人数。 假设企业本月发给员工的工资总和为sumSalary,该企业的员工总数为employeeNumber,
下面的程序代码计算该企业员工本月的平均工资,其中需要处理employNumber为0的情况。
【 Java 代码 】
import java.util.Scanner;
public class JavaMain {
static float average(float x, int y) throws Exception{
if (y ==0 ) throw new Exception( (1) );
return x/y;
}
static void caculate() throws Exception{
float sumSalary;
int employeeNumber;
Scanner sc = new Scanner( (2) );
try{
System.out.println("请输入当月工资总和与员工数:");
sumSalary = sc.nextFloat(); //从标准输入获得工资总和
employeeNumber = sc.nextInt(); //从标准输入获得员工数
float k = average(sumSalary,employeeNumber);
System.out.println("平均工资:" + k);
}
(3) (Exception e){
if(e.getMessage().equalsIgnoreCase("zero")){
System.out.println("请重新输入当月工资总和与员工数:");
sumSalary = sc.nextFloat();
employeeNumber = sc.nextInt();
float k = average(sumSalary,employeeNumber);
System.out.println("平均工资:" + k);
}
}
}
public 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)
第4题
阅读以下说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【 说明 】
现需要统计某企业员工的月平均工资,即该企业本月发给员工的工资总和除以员工人数。 假设企业本月发给员工的工资总和为sumSalary,该企业的员工总数为employeeNumber,
下面的程序代码计算该企业员工本月的平均工资,其中需要处理employNumber为0的情况。
【 Java 代码 】
import java.util.Scanner;
public class JavaMain {
static float average(float x, int y) throws Exception{
if (y ==0 ) throw new Exception( (1) );
return x/y;
}
static void caculate() throws Exception{
float sumSalary;
int employeeNumber;
Scanner sc = new Scanner( (2) );
try{
System.out.println("请输入当月工资总和与员工数:");
sumSalary = sc.nextFloat(); //从标准输入获得工资总和
employeeNumber = sc.nextInt(); //从标准输入获得员工数
float k = average(sumSalary,employeeNumber);
System.out.println("平均工资:" + k);
}
(3) (Exception e){
if(e.getMessage().equalsIgnoreCase("zero")){
System.out.println("请重新输入当月工资总和与员工数:");
sumSalary = sc.nextFloat();
employeeNumber = sc.nextInt();
float k = average(sumSalary,employeeNumber);
System.out.println("平均工资:" + k);
}
}
}
public 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)
第5题
A.Compilationfails.
B.aAaAaAaAAaaAaA
C.AAaaAaAaAaaAaA
D.AaAAAaaaAaAaAa
E.aAaAaAaAaAAAaa
F.Anexceptionisthrownatruntime.
第6题
A.apple:apple
B.carrot:apple
C.apple:banana
D.banana:apple
E.carrot:carrot
F.carrot:banana
第7题
A.a="A"
B.a="E" a="A"
C.a="E"
D.a="C"
第8题
A.a="A"
B.aa"E" a="A"
C.a="E"
D.a="C"
第9题
A.s1
B.s2
C.s2和s3
D.s2和s4
第10题
A.Setset=newTreeSet();
B.Setset=newHashSet();
C.Setset=newSortedSet();
D.Listset=newSortedList();
E.Setset=newLinkedHashSet();
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!