Skip to content

Instantly share code, notes, and snippets.

@digen21
Created March 27, 2022 18:50
Show Gist options
  • Save digen21/96670b37be60a2d05fdb853840b2d731 to your computer and use it in GitHub Desktop.
Save digen21/96670b37be60a2d05fdb853840b2d731 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class std {
int id;
String name;
void setData(int id, String name) {
this.id = id;
this.name = name;
}
void getdata() {
System.out.print(id + " " + name);
System.out.println("");
}
}
public class Student {
public static void main(String[] args) {
int id, n;
String name;
Scanner sc = new Scanner(System.in);
System.out.println("Enter no of Students: ");
n = sc.nextInt();
std[] s1 = new std[n];
for (int i = 0; i < n; i++) {
System.out.println("Enter Name: ");
name = sc.next();
System.out.println("Enter id;");
id = sc.nextInt();
s1[i] = new std();
s1[i].setData(id, name);
System.out.println("--------------------------------");
}
for (int i = 0; i < n; i++) {
s1[i].getdata();
System.out.println("--------------------------------");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment