java二維字符數組的輸入


java 二維字符數組輸入的方法有很多,這里簡單介紹一種:

import java.util.Scanner; public class test{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); //n行 int m = scan.nextInt();//m列 String[] temp= new String[n+1]; //字符串數組做中間變量 for(int i = 0; i< n; i++) { temp[i] = scan.next(); } char[][] p = new char[n][m]; // temp字符串數組轉為二維數組p[n][m]; for(int i = 0; i<n; i++) { for(int j = 0; j< m; j++) { p[i][j] = temp[i].charAt(j); System.out.println(p[i][j]); } } } }


免責聲明!

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



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