7 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. import java.util.Scanner;
    class DeleteSorted
    {
    public static void main(String args[])
    {int temp,index=0;
    Scanner scan=new Scanner(System.in);
    System.out.println("How many number you want to add");
    int n=scan.nextInt();
    int ar[]=new int[n];
    System.out.println("Enter Numbers");
    for (int i=0;i<n;i++)
    {
    ar[i]=scan.nextInt();
    }
    for(int j=0;j<n;j++)
    {
    for(int i=0;i<n;i++)
    {
    if(ar[j]<ar[i])
    {
    temp=ar[j];
    ar[j]=ar[i];
    ar[i]=temp;
    }
    }
    }
    System.out.println("Sorted array ");
    for (int i=0;i<n;i++)
    {
    System.out.print(ar[i]+" ");
    }
    System.out.println("\n Enter the Number you want to delete");
    int DelNum=scan.nextInt();
    for(int i=0;i<n;i++)
    {
    if(DelNum==ar[i])
    {
    index=i;
    break;
    }
    }
    for(int i=index;i<n-1;i++)
    {
    ar[i]=ar[i+1];
    }
    System.out.println("New Sorted array ");
    for (int i=0;i<n-1;i++)
    {
    System.out.print(ar[i]+" ");
    }

    }
    }

    ReplyDelete
  3. import java.util.Scanner;
    class D
    {
    public static void main(String args[])
    {
    Scanner obj=new Scanner(System.in);
    int n;
    System.out.println("Enter the value of n");
    n=obj.nextInt();
    int arr[]=new int[n];
    int temp,i,j,del_num;
    int tag=0;
    System.out.println("Enter the array");
    for(i=0;i<n;i++)
    {
    arr[i]=obj.nextInt();
    }
    for(i=0;i<n;i++)
    {
    for(j=i+1;j<n;j++)
    {
    if(arr[i]<arr[j])
    {
    temp=arr[i];
    arr[i]=arr[j];
    arr[j]=temp;
    }
    }
    }
    System.out.println("The sorted array in desecending order is=");
    for(i=0;i<n;i++)
    {
    System.out.println(arr[i]);
    }
    System.out.println("Enter the number to be deleted");
    del_num=obj.nextInt();
    for(j=0;j<n;j++)
    {
    if(del_num==arr[j])
    {
    for(i=j;i<n-1;i++)
    {
    arr[i]=arr[i+1];
    }
    tag=1;
    }
    }
    if(tag!=1)
    {
    System.out.println("number not found");
    System.out.println("The last sorted array is=");
    for(j=0;j<n;j++)

    System.out.println(arr[j]);
    }
    else
    {
    System.out.println("The last soretd array is");
    for(j=0;j<n-1;j++)
    System.out.println(arr[j]);

    }
    }
    }

    ReplyDelete
  4. import java.util.Scanner;
    public class DELETEARRAY
    {
    public static void main(String args[])
    {
    int temp,pos=0;
    Scanner scan=new Scanner(System.in);
    System.out.println("enter size of array:");
    int n=scan.nextInt();
    int ar[]=new int[n];
    System.out.println("Enter elements in array");
    for (int i=0;i<n;i++)
    {
    ar[i]=scan.nextInt();
    }
    for(int i=0;i<n;i++)
    {
    for(int j=0;j<n;j++)
    {
    if(ar[i]<ar[j])
    {
    temp=ar[i];
    ar[i]=ar[j];
    ar[j]=temp;
    }
    }
    }
    System.out.println("Sorted array is : ");
    for (int i=0;i<n;i++)
    {
    System.out.print(ar[i]+" ");
    }
    System.out.println(" Enter the Number which you want to delete");
    int num=scan.nextInt();
    for(int i=0;i<n;i++)
    {
    if(num==ar[i])
    {
    pos=i;
    break;
    }
    }
    for(int i=pos;i<n-1;i++)
    {
    temp=ar[i];
    ar[i]=ar[i+1];
    ar[i+1]=temp;
    }
    System.out.println("New Sorted array ");
    for (int i=0;i<n-1;i++)
    {
    System.out.print(ar[i]+" ");
    }
    }
    }
    output:
    enter size of array:
    5
    Enter elements in array
    12
    36
    8
    46
    21
    Sorted array is :
    8 12 21 36 46 Enter the Number which you want to delete
    21
    New Sorted array
    8 12 36 46

    ReplyDelete
  5. import java.util.Scanner;
    class Delete1{
    public static void main(String arr[]){
    Scanner obj=new Scanner(System.in);
    int n,no,i,j,flag=0;
    System.out.println("enter the value of no. of elements");
    n=obj.nextInt();
    int ar[]=new int[n];
    System.out.println("enter a sorted array");
    for(i=0;i<n;i++)
    ar[i]=obj.nextInt();
    System.out.println("enter the no. you want to delete");
    no=obj.nextInt();
    for(i=0;i<n;i++){

    if(no==ar[i]){

    for(j=i;j<n-1;j++)
    ar[j]=ar[j+1];

    flag=1;}
    }
    if(flag==0)
    System.out.println("element not found");
    for(i=0;i<n-1;i++)
    System.out.println(ar[i]);
    System.out.println("the above array is the sorted array");
    }
    }

    ReplyDelete
  6. import java.util.Scanner;
    class Delete{
    public static void main(String args[]){
    int n,i=0,j=0,temp=0,N;
    Scanner scan=new Scanner(System.in);
    int ar[]=new int[10];
    System.out.println("Enter the size");
    n=scan.nextInt();
    for(i=1;i<=n;i++)
    {
    System.out.println("Enter the value"+(i));
    ar[i]=scan.nextInt();
    }
    System.out.println("enter the element you want to delete from the array:");
    N=scan.nextInt();

    for(i=1;i<=n;i++)
    {


    if(ar[i]==N)
    {
    ar[i]=0;
    }

    }

    System.out.println("New array:");
    for(i=1;i<=n;i++)
    {
    if(ar[i]>0){
    System.out.println(+ar[i]);
    }
    }
    }
    }




















    ReplyDelete
  7. import java.util.Scanner;
    class Deletesort{
    public static void main(String args[]){
    int temp,count=0;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter the size:");
    int n=scan.nextInt();
    int ar[]=new int[n];
    System.out.println("Enter values:");
    for (int i=0;i<n;i++){
    ar[i]=scan.nextInt();
    }
    for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    if(ar[i]<ar[j]){
    temp=ar[i];
    ar[i]=ar[j];
    ar[j]=temp;
    }
    }
    }
    System.out.println("The Sorted array:");
    for(int i=0;i<n;i++){
    System.out.print(ar[i]+" ");
    }
    System.out.println("Enter the number you want to delete");
    int Delete=scan.nextInt();
    for(int i=0;i<n;i++){
    if(Delete==ar[i]){
    count=i;
    break;
    }
    }
    for(int i=count;i<n-1;i++){
    ar[i]=ar[i+1];
    }
    System.out.println("Array after deleting the element:");
    for (int i=0;i<n-1;i++){
    System.out.print(ar[i]+" ");
    }
    }
    }

    ReplyDelete