import java.io.*;
class arr
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
int ar[]=new int[100];
int n,i,j,pos,ch;
System.out.print("Enter number of element :-");
n=Integer.parseInt(br.readLine());
if(n<=99)
{
for(i=0;i<n;i++)
{
System.out.print("Enter any no :-");
ar[i]=Integer.parseInt(br.readLine());
}
do
{
System.out.println("\n1.Ele insert...");
System.out.println("2.Ele delete...");
System.out.println("3.Ele display...");
System.out.println("4.Exit");
System.out.print("Enter your choice :-");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.print("Enter position number :-");
pos=Integer.parseInt(br.readLine());
if(pos<n)
{
for(j=n-1;j>=pos-1;j--)
ar[j+1]=ar[j];
System.out.print("Enter new inserting element :-");
ar[j+1]=Integer.parseInt(br.readLine());
n++;
}
else
System.out.println("Sory invalid position number enterde.....");
break;
case 2:
System.out.print("Enter position number :-");
pos=Integer.parseInt(br.readLine());
if(pos<n)
{
for(j=pos-1;j<n;j++)
ar[j]=ar[j+1];
System.out.println("element deleted......");
n--;
}
else
System.out.println("Sory invalid position number enterde.....");
break;
case 3:
for(i=0;i<n;i++)
System.out.print(ar[i]+"\t");
System.out.println();
break;
case 4:
System.out.println("Program end.......");
break;
default:
System.out.println("Invalid enter select......");
}
}while(ch != 4 );
}
else
System.out.println("Out of range........");
}
}
No comments:
Post a Comment