小编use*_*612的帖子

解释一下,字符串是不可变的

我读了很多字符串对象是不可变的,只有字符串缓冲区是可变的.但是当我尝试这个程序时.我很迷惑.所以这个计划到底发生了什么.

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)

java string immutability

1
推荐指数
1
解决办法
361
查看次数

我的简单数组程序没有给出预期的输出

我写了一个简单的数组,我存储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

java arrays matrix

0
推荐指数
1
解决办法
302
查看次数

标签 统计

java ×2

arrays ×1

immutability ×1

matrix ×1

string ×1