Skip to content

Instantly share code, notes, and snippets.

@akashkumarcs19
Created June 23, 2021 05:15
Show Gist options
  • Save akashkumarcs19/b81bdc932854bc1d05309ab5d171144d to your computer and use it in GitHub Desktop.
Save akashkumarcs19/b81bdc932854bc1d05309ab5d171144d to your computer and use it in GitHub Desktop.
Nonprimitive_data_type_array
import java.util.Scanner;
public class StudentArray {
Scanner sc = new Scanner(System.in);
int rollno;
String name;
public StudentArray(int rollno, String name) {
this.rollno = rollno;
this.name = name;
}
StudentArray studentArray [] = new StudentArray[1];
public StudentArray(){};
public int getRollno() {
return rollno;
}
public void setRollno(int rollno) {
this.rollno = rollno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void insert (String name,int rollno,int position) {
studentArray[position -1]=new StudentArray(rollno,name);
}
//}
public void traverse() {
try {
for (int i = 0; i < studentArray.length; i++) {
System.out.println(studentArray[i].getName() + " " + studentArray[i].getRollno());
}
} catch(NullPointerException e) {
System.out.println("No value in the array");
}
}
public void deleteindex(int index){
studentArray[index].setRollno(Integer.MAX_VALUE);
studentArray[index].setName(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment