I want to make data of several people into objects and store them in the similar way below, but I don't know how to do it. I was just trying to trick you. As expected, there's an error. Please let me know.
```The programming language you use is Java public class Background {
private String name;
private long number;
private String birthday;
public Background(String name, long number, String birthday) {
this.name = name;
this.number = number;
this.birthday = birthday;
}
public static void main(String[] args) {
String name = ["Steve", "Dave", "Janny"]
int number = [1, 2, 3]
String birthday = ["2000", "2005", "2015" ]
int i = 0;
Background array[i] = (Background) new Background(name, number, birthday);
System.out.println(array[i].name);
System.out.println(array[i].number);
System.out.println(array[i].birthday);
}
class BackGround {
String name;
int number;
String birthday;
public BackGround(String name, int i, String birthday) {
this.name = name;
this.number = i;
this.birthday = birthday;
}// Background constructor
public String toString(){
return "("+name+","+number+","+birthday+")";
}// ToString method
}// Background Class
public class Ex01{
public static void main(String[] args) {
BackGround[] arr = { new BackGround("Steve",1,"2000")
,new BackGround("Dave",2,"2005")
,new BackGround("Janny",3,"2015")
};
for(int i=0; i<arr.length; i++){
System.out.println(arr[i]);
}//--for statement
}//-- }//-- main
} // Ex01 Class
public class Background {
public static void main(String[] args) {
String[] name = {"Steve", "Dave", "Janny"};
int[] number = {1, 2, 3};
String[] birthday = {"2000", "2005", "2015" };
String[] a = new String[3]; // name + number + birthday Create an array of length 3 to hold information
for(int i=0;i<3;i++){
a[i] = "["+name[i]+","+number[i]+","+birthday[i]+"]";
}// Include [name, number, birthday] information in arrays a[0] to a[2]
for(int i=0;i<3;i++){
System.out.println(a[i]);
} // a[0] to a[2] output
}//main end
}//class end
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
582 PHP ssh2_scp_send fails to send files as intended
619 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.