1 数组的逆序输出1
import java.util.Scanner;
public class P1427 {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int [] arr = new int [100];
System.out.println("请输入多个正整数(输入-1结束):");
int i=0;
do{
arr[i] = input.nextInt();
i++;
}while(arr[i-1] != -1);
System.out.println("你输入的数组是:");
for(int j2 = 0;j2 < i-1;j2++){
System.out.println(arr[j2]+" ");
}
System.out.println("你输入的数组逆序输出为:");
for(int j2=0;j2<i-1;j2++){
System.out.println(arr[i-2-j2] + " ");
}
}
}
2 数组你逆序输出2
public class P1427 {
public static void main(String[]args){
int a[] = {1, 2, 3, 4, 5};
for(int i = 0; i<a.length; i++){
System.out.print(a[i] + " ");
}
System.out.print("\n");
int n = a.length;
for(int i = 0; i < n/2; i++){
int temp = a[i];
a[i] = a[n-i-1];
a[n-i-1] = temp;
}
for(int i = 0; i<a.length; i++){
System.out.print(a[i] + " ");
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)