java 数组如何挑换位置,请帮忙列出代码
需求String[]arrStrs={"a","b","c","d"};要求输出:String[]newStrs={"d","c","b","a"};...
需求String [] arrStrs={"a","b","c","d"};
要求输出:String [] newStrs={"d","c","b","a"}; 展开
要求输出:String [] newStrs={"d","c","b","a"}; 展开
展开全部
public static void main(String[] args) {
String [] arr = {"a","b","c","d"};
String [] arrNew = new String[arr.length];
int size = 0;
for(int i = arr.length-1;i>=0;i--){
arrNew[size] = arr[i];
size++;
}
for(int j =0;j<arrNew.length;j++){
System.out.println("新的数组》》》"+arrNew[j]);
}
}
应该是可以的,你试试,希望能帮到你
String [] arr = {"a","b","c","d"};
String [] arrNew = new String[arr.length];
int size = 0;
for(int i = arr.length-1;i>=0;i--){
arrNew[size] = arr[i];
size++;
}
for(int j =0;j<arrNew.length;j++){
System.out.println("新的数组》》》"+arrNew[j]);
}
}
应该是可以的,你试试,希望能帮到你
展开全部
class test1{
public static void main(String[] args){
char[] arrStrs={'a','b','c','d'};
char[] newStrs=new char[4];
int j=0;
for(int i=3;i>=0;i--){
newStrs[j]=arrStrs[i];
j++;
}
for(int a=0;a<newStrs.length;a++){
System.out.println("newStrs:"+newStrs[a]);
}
}
}
public static void main(String[] args){
char[] arrStrs={'a','b','c','d'};
char[] newStrs=new char[4];
int j=0;
for(int i=3;i>=0;i--){
newStrs[j]=arrStrs[i];
j++;
}
for(int a=0;a<newStrs.length;a++){
System.out.println("newStrs:"+newStrs[a]);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询