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

熱點內容
納粹命令 瀏覽:586
什麼講鬼故事app 瀏覽:965
程序員級升 瀏覽:87
怎樣關閉照片加密 瀏覽:522
文件夾變拉鏈 瀏覽:607
伺服器未在運行什麼意思 瀏覽:405
單片機應用大賽 瀏覽:462
博格上海壓縮機有限公司 瀏覽:27
招行車貸解壓有費用嗎 瀏覽:702
總統命令小說 瀏覽:818
安卓手機為什麼卡成狗 瀏覽:384
廣州市公司軟體加密 瀏覽:230
燈光設計手冊pdf 瀏覽:767
java虛線 瀏覽:428
androidio流 瀏覽:799
伺服器怎麼改nvr 瀏覽:939
真空壓縮袋怎樣打開 瀏覽:80
證券市場基礎知識pdf2012 瀏覽:720
mastercam自動編程視頻 瀏覽:11
如何得知加密類型 瀏覽:42