下面程序执行后,屏幕上显示的应是______。 public class Testl0 { public static void main(String[] args) {

admin2010-02-22  30

问题 下面程序执行后,屏幕上显示的应是______。       public class Testl0       {             public static void main(String[] args)             {                   char char1[]  = {’t’,  ’e’,  ’s’,  ’t’};                   char char2[] = (’t’,  ’e’,  ’s’,  ’t’,  ’1 };                   String s1 = new String(char1);                   String s2 = new String(char2,  0,  4);                   System.out.println (si.equal (s2));             }       }     

选项 A、true         
B、假
C、test            
D、编译错误

答案1

解析 首先可以通过字符数组来生成一个字符串对象:
   String(char[]value);
   String(char[]value,int startlndex,int numChars);
   其中,startlndex指定字符串在数组中的起始下标,numChars表示字符个数。然后再测试字符串是否相等,可调用equal()方法,两串相等则返回true,否则返回false。
转载请注明原文地址:https://kaotiyun.com/show/M4np777K
0

最新回复(0)