1、计算机二级 JAVA-60 及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:3,分数:100.00)1.本程序比较两个字符串“Welcome to China!“和“Welcome you back home!“的大小(即对应字符相比较,出现第一个不相等的字符时,大的所在的字符串大,小的所在的字符串小,字符的比较相当于字符对应的ASCII 的比较)。 public class exam_43 public static void main(String args) String str1=“Welcome to China!“; String str2=“W
2、elcome you back home!“; int l=str1.length()str2.length()?_; char c1=, c2=; for(int i=0; i1; i+) c1=str1.charAt(i); c2=str2.charAt(i); if(_) _; if(c1c2) System.out.println(“+str1+“+“+“+str2+“); else System.out.println(“+str1+“+“+“+str2+“); (分数:30.00)_2.本程序的功能是定义了一个长度为 5 的一维数组,然后将 04 分别赋给数组中的各个元素,最后按数
3、组下标的逆序打印输出。 public class exam_44 public static void main(String args) int arr; _; int i; for(_; i+) arri=i; for(_; i-) System.out.print(“arr“+i+“=“+arri+“ “); (分数:30.00)_3.本程序的功能是求一个一维数组 arr=13,7,21,7,9,69,34,85)中的最大值。 public class exam_45 public static void main(String args) int arr=13,7,21,7,9,69,
4、34,85); int 1=arr.length; int temp; _; for(int i=1; i1; i+) if(_) _; System.out.println(“The max:“+temp); (分数:40.00)_计算机二级 JAVA-60 答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:3,分数:100.00)1.本程序比较两个字符串“Welcome to China!“和“Welcome you back home!“的大小(即对应字符相比较,出现第一个不相等的字符时,大的所在的字符串大,小的所在的字符串小,字符的比较相当于字符对应的A
5、SCII 的比较)。 public class exam_43 public static void main(String args) String str1=“Welcome to China!“; String str2=“Welcome you back home!“; int l=str1.length()str2.length()?_; char c1=, c2=; for(int i=0; i1; i+) c1=str1.charAt(i); c2=str2.charAt(i); if(_) _; if(c1c2) System.out.println(“+str1+“+“+“+
6、str2+“); else System.out.println(“+str1+“+“+“+str2+“); (分数:30.00)_正确答案:(str1.length():str2.length() c1!=c2 break)解析:2.本程序的功能是定义了一个长度为 5 的一维数组,然后将 04 分别赋给数组中的各个元素,最后按数组下标的逆序打印输出。 public class exam_44 public static void main(String args) int arr; _; int i; for(_; i+) arri=i; for(_; i-) System.out.prin
7、t(“arr“+i+“=“+arri+“ “); (分数:30.00)_正确答案:(arr=new int5 1=0; 15 i=4; i=0)解析:3.本程序的功能是求一个一维数组 arr=13,7,21,7,9,69,34,85)中的最大值。 public class exam_45 public static void main(String args) int arr=13,7,21,7,9,69,34,85); int 1=arr.length; int temp; _; for(int i=1; i1; i+) if(_) _; System.out.println(“The max:“+temp); (分数:40.00)_正确答案:(temp=arr 0 temparr i temp=arr i)解析: