怎么將從Java控制臺輸入的數組進行逆序輸出?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

實現在控制臺輸入一個數組,并讓其逆序輸出
源碼:
import java.util.Scanner;
public class Test01 {
public static void main(String[] args){
System.out.println("請輸入五個數");
int[]l=new int [5];
for(int i=0;i<5;i++)
l[i]=new Scanner(System.in).nextInt();
Test01 sorter=new Test01();
sorter.ReverseSort(l);
}
public void ReverseSort (int[] l) {
int len=l.length;
for(int i=0;i<len/2;i++){
int temp=l[i];
l[i]=l[len-1-i];
l[len-1-i]=temp;
}
System.out.println("反轉后");
show(l);
System.out.println();
}
public static void show(int[] l) {
for(int i:l){
System.out.print(i+" ");
}
}
}
本文名稱:怎么將從Java控制臺輸入的數組進行逆序輸出-創新互聯
分享網址:http://www.yijiale78.com/article36/dddjpg.html
成都網站建設公司_創新互聯,為您提供企業網站制作、建站公司、外貿網站建設、電子商務、微信小程序、App開發
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯