java数组基础
java数组基础publicclassshuzu_fuzhi2{publicstaticvoidmain(String[]args){int[]shuzuA={45,35...
java数组基础public class shuzu_fuzhi2 {
public static void main(String[] args){
int[] shuzuA={45,35,57,78,54,55};
int[] shuzuB=new int[shuzuA.length];
for(int i=0;i<shuzuA.length;i++){
shuzuB[i]=shuzuA[i];
shuzuB[i]++;
System.out.println("shuzuA["+i+"]="+shuzuA[i]);
System.out.println("shuzuB["+i+"]="+shuzuB[i]);
}
}
}
为什么输出是从1下标开始。而且每个值都加了一 展开
public static void main(String[] args){
int[] shuzuA={45,35,57,78,54,55};
int[] shuzuB=new int[shuzuA.length];
for(int i=0;i<shuzuA.length;i++){
shuzuB[i]=shuzuA[i];
shuzuB[i]++;
System.out.println("shuzuA["+i+"]="+shuzuA[i]);
System.out.println("shuzuB["+i+"]="+shuzuB[i]);
}
}
}
为什么输出是从1下标开始。而且每个值都加了一 展开
2个回答
展开全部
public static void main(String[] args) {
//定义数组 初始化长度并赋值
int[]shuzuA={45,35,57,78,54,55};
//定义数组并初始化长度
int[] shuzuB=new int[shuzuA.length];
//循环shuzuA 数组
for(int i=0;i<shuzuA.length;i++){
//将A 数组的值 赋给B
shuzuB[i]=shuzuA[i];
//B数组的值加+ 注意 shuzuB[i]是取值 ++是自增1 也就是当前i的坐标值+1
//相当于 int b= shuzuB[i]+1; shuzuB[i]=b;
shuzuB[i]++;
System.out.println("shuzuA["+i+"]="+shuzuA[i]);
System.out.println("shuzuB["+i+"]="+shuzuB[i]);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询