0% found this document useful (0 votes)
8 views

A Java code to add or delete other number of N number of students.

Uploaded by

thanushree77777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

A Java code to add or delete other number of N number of students.

Uploaded by

thanushree77777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

A Java code to either add or delete Aadhar number of n Number of students.

import java.util.*;
class r14
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of students");
int n=sc.nextInt();
int d=0,a=0;
int ar[]=new int [n+1];
System.out.println("Enter Aadhaar number for "+n+" student " );
for (int i = 0; i < n; i++)
{
ar[i] = sc.nextInt();
}
System.out.println("\nMenu:");
System.out.println("1. Add Aadhaar number");
System.out.println("2. Delete Aadhaar number");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();//to store the choice
if(choice==1)
{
System.out.println("Enter Aadhaar number to add: ");
a = sc.nextInt();
System.out.println("Input the posistion of the number to be inserted");
int pos=sc.nextInt();
for(int i=n-1;i>=pos-1;i--)//loop th shift elemnts
{
ar[i+1]=ar[i];//shifting takes place.
}
ar[pos-1]=a;//elemest is being added.
System.out.println("Updated List :");
for(int i=0;i<n+1;i++)
{
System.out.println(ar[i]);//printing new list.
}
System.out.println();
}
else if (choice == 2)
{
System.out.print("Enter Aadhaar number to delete: ");
d = sc.nextInt();
System.out.println("Input the posistion of the number to be deleted");
int pos=sc.nextInt();
for(int i=pos;i<n;i++)
{
ar[i-1]=ar[i];//element is being deleted

}
System.out.println("Updated List :");
for(int i=0;i<n-1;i++)
{
System.out.println(ar[i]);//printing new list.
}
System.out.println();
}
else
{
System.out.println("INVALID INPUT OF CHOICE");
}
}
}

You might also like