在java中如何给数组赋值_Java如何在类数组中赋值importjava.util.*;publicclassJavaA{/***@paramargsthecommandlinearguments*/publicstaticvoidmain(String[]args) {Book[]a1=newBook[20];for(inti=0;i<20;i++){Booka1[i]=newBook("...
import java.util.*;
public class JavaA {
/**
数组全部赋值为1* @param args the command line arguments
*/
public static void main(String[] args) {
Book[] a1=new Book[20];
for(int i=0;i<20;i++){
Book a1[i]=new Book("ab","cd","i","ef","29");
}
for(int i=0;i<20;i++){
System.out.println(a1[i]);
}
}
public class Book {
private String auther;
private String BookName;
private int number;
private String press;
private double prices;
public Book(){}
public Book(String auther,String BookName,int number,String press,double prices){
this.auther=auther;
this.BookName=BookName;
this.number=number;
this.press=press;
this.prices=prices;
}
public String getAuther(){
return auther;
}
public String getBookName(){
return BookName;
}
public int getNumber(){
return number;
}
public String getPress(){
return press;
}
public double getPrices(){
return prices;
}
public String toString(){
String s=auther+" "+BookName+" "+number+" "+press+" "+prices; return s;
}
}
我想在定义的a1数组中赋值该怎么办?
展开
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论