em đã viết ra ra code nhâp tung độ và hoành độ rồi xuất ra màn hình, nhưng chưa hiểu sao chương trình xuất ra màn hình giá trị tđ và hđ là 0 hết, mong các bác giúp em chỉnh sửa phần code của em ạ
public class Diem {
Diem() {
}
private int td,hd;
Diem(int x, int y){
hd = x;
td = y;
}
Diem nhapdiem(int k) throws IOException{
int td,hd;
Scanner nhap = new Scanner(System.in);
System.out.println("Nhap toa do diem");
System.out.println("Tung do: ");
td = nhap.nextInt();
Scanner nhap1 = new Scanner(System.in);
System.out.println("Hoanh do: ");
hd = nhap1.nextInt();
Diem toado = new Diem( td, hd);
return toado;
}
public void setTd(int td) {
this.td = td;
}
public void setHd(int hd) {
this.hd = hd;
}
public int getTd() {
return this.td;
}
public int getHd() {
return this.hd;
}
public void Hienthidiem() {
System.out.println( "(" + this.hd + "," + this.td + ")" );
}
public static void main(String[] args) throws IOException {
int n = 2;
Diem[] listDiem = new Diem[n];
for(int i=0; i<n; i++) {
Diem diem = new Diem();
diem.nhapdiem();
listDiem[i] = diem;
}
for(int i = 0;i < n; i ++){
Diem k = new Diem();
k.Hienthidiem(listDiem[i]);
}
}
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?