導航:首頁 > 編程語言 > java數組如何輸入

java數組如何輸入

發布時間:2024-04-13 21:41:34

① 怎樣用java輸入一個char型的二維數組

代碼如下:

以下是文字版的代碼:

import java.util.Scanner;

public class Test{

public static void main(String []args) {

Scanner in=new Scanner(System.in);

System.out.print("請輸入數組c第一維的元素個數:");

int n=in.nextInt();

char[][] c=new char[n][];

int[] m=new int[n];

int i,k;

String s;

for(i=0;i<n;i++)

{

System.out.print("請輸入數組c["+i+"]的元素個數:");

m[i]=in.nextInt();

c[i]=new char[m[i]];

for(k=0;k<m[i];k++)

{

System.out.print("請輸入c["+i+"]["+k+"]:");

s=in.next();

c[i][k]=s.charAt(0);

}

}

in.close();

System.out.println("輸入的二維數組如下:");

for(i=0;i<n;i++)

{ for(k=0;k<c[i].length;k++)

{

System.out.print(c[i][k]+" ");

}

System.out.println();

}

}

}

② java 數組怎麼輸入值

int[] array = new int[10];//數組長度為10
for(int i=0;i<array.length;i++){
array[i] = i; //這里也可以用鍵盤輸入語句,如果用鍵盤輸入語句就要閑定義輸入流BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 定義流在循環外面定義,然後array[i] = Integer.parseInt(br.readLine(); 這樣就可以了。
}
這樣就用循環把數組初始化了!

③ java 鍵盤輸入二維數組

輸完六個數字後加一個符號,比如 「@」
在java判斷輸入 @的時候,停止錄入。

--------------------

import java.util.*;

public class InputDemo {
public static void main(String[] args) {
int x;
int y;

Scanner reader = new Scanner(System.in);
System.out.print("請輸入二維數組的行數x:");
x = reader.nextInt();
System.out.print("請輸入二維數組的列數y:");
y = reader.nextInt();
int[][] n = new int[x][y];
int[] arr = new int[x*y];

int count = 0;
while(reader.hasNextInt()){
arr[count] = reader.nextInt();
count++;
if(count == x*y)
break;
}

for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
n[i][j] = arr[3*i+j];
}
}
System.out.println("您輸入的數組為:");
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
System.out.print(n[i][j] + "\t");
}
System.out.println();
}
}
}

④ java數組怎麼輸入數據

1.新建Java工程和自定義類。

閱讀全文

與java數組如何輸入相關的資料

熱點內容
不去互聯網程序員 瀏覽:550
電腦qq郵箱解壓的圖片保存在哪裡 瀏覽:544
嵌入命令行 瀏覽:91
檔案為什麼被加密 瀏覽:485
十天學會單片機13 瀏覽:875
榮耀怎麼設置讓app一直運行 瀏覽:993
共享文件夾能在哪裡找到 瀏覽:435
旅遊訂旅店用什麼app 瀏覽:239
一個女程序員的聲音 瀏覽:496
魔術app怎麼用 瀏覽:340
單片機有4個8位的io口 瀏覽:897
win10rar解壓縮軟體 瀏覽:169
plc教程pdf 瀏覽:668
pythonshell清屏命令 瀏覽:279
檢測到加密狗注冊伺服器失敗 瀏覽:205
解壓後手機如何安裝 瀏覽:519
極客學院app為什麼下架 瀏覽:14
圖片批量壓縮綠色版 瀏覽:656
東北程序員帥哥 瀏覽:709
加密封條風噪小 瀏覽:975