導航:首頁 > 編程語言 > java生成數組

java生成數組

發布時間:2023-03-01 07:25:25

java怎麼創建一個數組,每個元素是一個數組

用 ArrayList 里 放數組吧,ArrayList 本身就是一數組類型存放的,你那種現在還不行,除非你自己封裝一個,數組的方法。

❷ java中怎麼創建對象數組

//如果你是初學JAVA,建議你看看這段代碼,裡面有一些基本技巧
//有疑問可以問我!

import java.io.*;

public class StudentInformation {

public static void main(String args[]) throws IOException {
Student[] st = new Student[5];// 第一個錯誤
int i = 0;
st[i++] = new Student().setStudent("WangZhen", 20, 1, 1.76);
st[i++] = new Student().setStudent("YangZhen", 21, 2, 1.66);
st[i++] = new Student().setStudent("Wangqiang", 19, 3, 1.86);
st[i++] = new Student().setStudent("XiaoMing", 18, 4, 1.71);
st[i++] = new Student().setStudent("XiaoHong", 22, 5, 1.74);
for (i = 0; i < st.length; i++)
st[i].display();
System.out.println("請輸入要查詢學生的姓名");
String str;
BufferedReader buf;
buf = new BufferedReader(new InputStreamReader(System.in));
str = buf.readLine();
for (i = 0; i < st.length; i++) {
if (st[i].name.equals(str)) {
System.out.println("所要查找學生為");
st[i].display();
}
}

}

}

class Student {
String name;

int age;

int num;// 學號

double high;// 身高

public void display() {
System.out.println("姓名:" + name + "\t年齡:" + age + "\t身高:" + high + "\t學號:" + num);
}

public Student setStudent(String n, int a, int nu, double h) {
name = n;
age = a;
num = nu;
high = h;
return this;
}
}

❸ java中怎麼創建一個數組

Java 中創建數組的基本格式為 type[] varname = new type[size]{item1, item2, item3},其中 type 表示元素的類型, size 表示創建數組的大小,在指定後面所有元素的情況下,這個大小可以省略,後面花括弧括起來的部分,用於指定元素,如果指定了大小,可以不要後面的部分,如以下語句軍創建了一個數組;
int[] = new int[1]; // 創建一個長度為1 的整形數組
int[] = new []{1}; // 創建一個長度為1,第一個元素的值為1;

閱讀全文

與java生成數組相關的資料

熱點內容
手機除了主板還有什麼app 瀏覽:182
如何還原在伺服器上刪除的文件 瀏覽:851
pdf轉成黑白的 瀏覽:20
程序員為什麼是單身 瀏覽:928
選項卡中的命令組被稱為什麼 瀏覽:261
navicatlinux破解 瀏覽:612
加密視頻可以用採集卡嗎 瀏覽:292
php正則表達式2 瀏覽:482
手機編譯的c程序怎麼安裝 瀏覽:222
vue編譯cdn 瀏覽:933
單片機矩陣鍵盤顯示 瀏覽:228
約束邊緣柱必須加密嗎 瀏覽:310
android學到什麼程度 瀏覽:375
如何加密一個小區 瀏覽:315
51單片機控制三相控制器 瀏覽:815
手機上什麼解壓軟體可以強制解壓 瀏覽:789
win7有自帶編譯器嗎 瀏覽:548
轉接器連了沒有文件夾 瀏覽:578
二手開利螺桿壓縮機 瀏覽:317
有php基礎學java要多久 瀏覽:308