我读了很多字符串对象是不可变的,只有字符串缓冲区是可变的.但是当我尝试这个程序时.我很迷惑.所以这个计划到底发生了什么.
class Stringss {
public static void main(String[] args) {
String s="hello";
String ss=new String("xyz");
System.out.println(ss);
System.out.println(s);
s="do";
ss=new String("hello");
System.out.println(s);
System.out.println(ss);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是
xyz
hello
do
hello
Run Code Online (Sandbox Code Playgroud) 我写了一个简单的数组,我存储3x3矩阵.但是当我运行代码时,它不会给出3x3矩阵.只提供一列作为输出.
class sucks
{
public static void main(String[] args)
{
int g[][]=new int[3][3];
int h,k,l=0;
for(k=0;k<3;k++)
{
for(h=0;h<3;h++)
{
g[k][h]=l;
l++;
}
}
for(k=0;k<3;k++)
{
for(h=0;h<3;h++)
{
System.out.print(g[k][h]+" ");
System.out.println();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出是这样的
0
1
2
3
4
五
6
7
8