1、计算机二级 JAVA-54及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:3,分数:100.00)1.本程序的功能是找出字符串“My name is Tom, I come from China.“中的大写字母,并打印输出。 public class exam_31 public static void main(String args) String str=“My name is Tom, I come from China.“; _; int i=0; while(ilen) char c=str.charAt(i); if(_) System.out
2、.print(c+“ “); _; (分数:30.00)_2.本程序计算两个整数 25和 7的商和余数。 public class exam_32 public static void main(String args) _; num1=25; num2=7; int res1, res2; _; _; System.out.println(num1+“/“+num2+“商:“+res1+“余:“+res2); (分数:30.00)_3.本程序提取字符串“China is a great country.“中的前 5个字符生成一个新的字符串,并将剩余字符组成另外一个新的字符串,最后将两个新的字
3、符串连接输出。 public class exam_33 public static void main(String args) String str=“China is a great country.“; _; headstr=str.substring(_); trailstr=str.substring(_); System.out.println(headstr+trailstr); (分数:40.00)_计算机二级 JAVA-54答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:3,分数:100.00)1.本程序的功能是找出字符串“My name
4、is Tom, I come from China.“中的大写字母,并打印输出。 public class exam_31 public static void main(String args) String str=“My name is Tom, I come from China.“; _; int i=0; while(ilen) char c=str.charAt(i); if(_) System.out.print(c+“ “); _; (分数:30.00)_正确答案:(int len=str.length() c=A num1=25; num2=7; int res1, res
5、2; _; _; System.out.println(num1+“/“+num2+“商:“+res1+“余:“+res2); (分数:30.00)_正确答案:(int num1, num2 res1=num1/num2 res2=num1%num2)解析:3.本程序提取字符串“China is a great country.“中的前 5个字符生成一个新的字符串,并将剩余字符组成另外一个新的字符串,最后将两个新的字符串连接输出。 public class exam_33 public static void main(String args) String str=“China is a great country.“; _; headstr=str.substring(_); trailstr=str.substring(_); System.out.println(headstr+trailstr); (分数:40.00)_正确答案:(String headstr, trailstr 0, 5 5, str.length()-1)解析: