this program ask inputs user: name of 5 students , addresses creating arrays of objects , displaying them.
package stringdisplay; import java.util.scanner; public class student { string name; string address; student[] studentarray = new student[5]; public void setinfo() { scanner username = new scanner(system.in); (int = 0; < 5; i++) { student student = new student(); system.out.print("enter name:"); student.name = username.nextline(); system.out.print("enter address:"); student.address = username.nextline(); studentarray[i] = student; } } public void displayinfo() { (int = 0; < 5; i++) { student student = studentarray[i]; system.out.print("name:" + student.name); system.out.print("address:" + student.address); } } public static void main(string[] args) { student info = new student(); info.setinfo(); student display = new student(); display.displayinfo(); } }
student info = new student(); info.setinfo(); student display = new student(); display.displayinfo();
read simple english of code making object "info" of student class , setting info in that....
and making new object of student class "display" there nothing in display object display because info saved in info object.
hope got problem...
Comments
Post a Comment