我是一个Java新手,下面代码的逻辑是什么?
我是java的新手。下面代码的逻辑是什么>我是一个Java新手,下面代码的逻辑是什么?,java,Java,我是java的新手。下面代码的逻辑是什么> public class Main { public static void main(String[] args) { int[] numbers = {1, 2, 3}; int length = numbers[2]; char[] chars = new char[length]; chars[numbers.length-1] = 'y'; System.
public class Main {
public static void main(String[] args) {
int[] numbers = {1, 2, 3};
int length = numbers[2];
char[] chars = new char[length];
chars[numbers.length-1] = 'y';
System.out.println("Done!");
}
}
请遵循每个步骤中提到的注释
public class Main {
public static void main(String[] args) {
int[] numbers = {1, 2, 3}; // create a new array of intergers as {1,2,3}
int length = numbers[2]; // assign 3 to variable 'length'
char[] chars = new char[length]; // create a char array of size 3
chars[numbers.length-1] = 'y'; // assign 'y' to index 2 of chars array
System.out.println("Done!"); // print DONE to console ( and this will print everytime as no conditions involved)
}
}
这只是向你展示如何声明数组和调整数组大小。这是一个非常脆弱的代码,没有太多作用,它所做的并不是特别有用。也许你会发现有用的。糟糕的标题。重写以总结您的具体技术问题。据我所知,它创建了3个整数,分别为1、2和3。当int的长度等于2时,它将打印完成!。但我不明白下面代码的含义;char[]chars=新字符[长度];字符[number.length-1]=“y”;有人能帮我吗?非常感谢。