1:写出程序段运行后array数组的值(),说明原因
public static void aMethod{int[] a}
for(int i=0;i<a.length;i++)
{
a[i]=a[a.length/2+i];
}
}
public static void main(String args[])
int[]array=int[3];
array[0]=1;
array[1]=2;
array[2]=3;
aMethod(array);
}
A {1,2,3} B {3,2,1} C {2,1,3} D {1,1,1}2 String s="hello";
String t="hello";
char c[]={'h','e','l','l','o'};
下面()表达式返回false:
A s.equals(t) B t.equals(c) C s==t D c.equals(new String("hello")
3 这个语句是否正确:int a[][]={{1,3},{2,3,4},{1,2}};
4
public static void aMethod{int[] a}
for(int i=0;i<a.length;i++)
{
a[i]=a[a.length/2+i];
}
}
public static void main(String args[])
int[]array=int[3];
array[0]=1;
array[1]=2;
array[2]=3;
aMethod(array);
}
A {1,2,3} B {3,2,1} C {2,1,3} D {1,1,1}2 String s="hello";
String t="hello";
char c[]={'h','e','l','l','o'};
下面()表达式返回false:
A s.equals(t) B t.equals(c) C s==t D c.equals(new String("hello")
3 这个语句是否正确:int a[][]={{1,3},{2,3,4},{1,2}};
4
2答案是b
3正确.
我觉得他们都是new了一个新的对象,但为什么s==t???
如果写成这个样子:
String s = new String("hello");
String t = new String("hello");
就是False!!!
所以我觉得编译器肯定优化了
String s = new String("hello");
String t = s;
因为String是Final类,所以不能被修改。 t = s 也没什么的。。
2:B //引用名错
3:对。//数组initial
故AC对,BD不对
正确的答案是
1.地址越界
2BD
3对
String t="hello"; 是一个字符串 有'\0'结束
char c[]={'h','e','l','l','o'}; 只是字符数组 没有'\0'结束
这个是c/c++不能比较的,
1不用说了
2bd java里的string就是一个对象不是c里面的字符的串
3是不是这样的{1,3,0}{2,3,4}{1,2,0}
是不是这样的{1,3,0}{2,3,4}{1,2,0}?
应该是这样:{{1,3},{2,3},{1,2}} 因为{2,3,4}中有三个元素,而a[][]定义的是一个二维数据,所以后面的4在存储过程中将会被丢弃
String s="hello";
String t="hello";
s和t应该是字符串对象阿,直接用==来比较的话应该是比较他们的地址,怎么可能返回true呢,一定应该是false阿
难道这样声明就是字符串变量,只有用new才是对象么?偶基本功不好,达人帮我确认以下我的想法