java中如何在鍵盤中輸入一串數字然后存入數組中?


import java.util.Scanner;

public class Tset {

public static void main(String[] args) {

System.out.println("請輸入三個數:");

Scanner in = new Scanner(System.in);

int[] b=new int[3];

for(int i=0;i<b.length;i++){

b[i]=in.nextInt();

}

//遍歷

for(int i=0;i<b.length;i++){

System.out.println("b["+i+"]="+b[i]);

}

}

}

記得,輸入一個數按下回車鍵

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM