-3
개체 배열에서 하나의 개체를 인쇄하려고하는데 배열에 5 개의 개체가 포함되어 있는데 개체 하나만 인쇄하는 방법을 묻습니다 [ 1]?개체 배열에서 하나의 요소를 인쇄하는 방법
public static void main(String args[]){
Customer[] store = new Customer[5];
Customer c = new Customer(1, "Szabi", "Master");
Console console = new Console();
store[0] = new Customer(1, "Szabi", "Finchley");
store[1] = new Customer(2,"Anca", "Finchley") ;
store[2] = new Customer (3, "Deniz","Cricklewood");
store[3] = new Customer(4,"Suzanna", "Cricklewood") ;
store[4] = new Customer (5, "Lavinia", "Ealing");
//How do I print out just store[0] or just store[1]?
}
내가 예를 들어 저장소와 같은 특정 인덱스에 인쇄하는 데 문제가 있어요 [1] 또는 항상 가게에서 값을 출력하므로 저장 [0] [4], 아무리 내가 넣어하지 무엇을 대괄호. 다음과 같이 고객 클래스는 다음과 같습니다
package Eldorado;
import java.util.Arrays;
public class Customer implements CustomerItem , Comparable<Customer> {
static int id;
static String name;
static String address;
public Customer(){
id=0;
name=null;
address=null;
}
public Customer(int _id, String _name, String _address){
this.id=_id;
this.name=_name;
this.address=_address;
}
public void setId(int _id){
this.id=_id;
}
public void setName(String _name){
this.name=_name;
}
public void setAddress(String _address){
this.address=_address;
}
@Override
public int getId(){
return id;
}@Override
public String getName(){
return name;
}@Override
public String getAddress(){
return address;
}@Override
public boolean equals(CustomerItem other){
Customer a = new Customer();
Customer b = new Customer();
if(a.compareTo(b)==0){
return true;
}else{
return false;
}
}@Override
public int compareTo(Customer that){
if(this.id==that.id&&this.name==that.name&&this.address==that.address){
return 0;
}else if(this.id>that.id){
return 1;
}else{
return -1;
}
}
@Override
public String toString(){
return Integer.toString(getId())+getName()+getAddress();
}
}
'System.out.println (store [1]);'!? – luk2302
인쇄 방법에'[0]'또는'store [1]'을 전달하면 어떻게됩니까? – Pshemo
이 질문입니까? 인쇄 할 때'store [0]'또는'store [1]'을 사용하는 것을 멈추게하는 것은 무엇입니까? –