導航:首頁 > 編程語言 > 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生成數組相關的資料

熱點內容
macpdfword轉換器 瀏覽:904
壓縮面膜是什麼材質 瀏覽:353
抖音發布作品怎麼建文件夾 瀏覽:13
安卓如何更改谷歌地區 瀏覽:273
airpods為什麼安卓連上聲音很大 瀏覽:510
聯想伺服器按鈕怎麼開不了機 瀏覽:93
蘋果xrapp程序庫沒有了怎麼辦 瀏覽:843
在上海程序員一個月多少工資 瀏覽:326
k歌解壓圖片 瀏覽:579
cad中清理多餘圖層的命令 瀏覽:989
華為nova8xe是安卓什麼 瀏覽:58
湯姆貓伺服器為什麼免費 瀏覽:274
safenet加密狗怎麼用 瀏覽:41
phpsql查詢變數 瀏覽:104
地磅儀表盤加密方法 瀏覽:480
brew安裝php環境 瀏覽:829
電腦版釘釘如何加密 瀏覽:709
android動畫結合 瀏覽:925
androidfb0 瀏覽:579
我的世界怎麼給伺服器稱號 瀏覽:462