7 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. import java.util.Scanner;
    class InsertSorted
    {
    public static void main(String args[])
    {
    int temp;
    Scanner scan=new Scanner(System.in);
    System.out.println("How many number you want to add");
    int n=scan.nextInt();
    n+=1;
    int ar[]=new int[n];
    System.out.println("Enter Numbers");
    for (int i=0;i<n-1;i++)
    {
    ar[i]=scan.nextInt();
    }
    for(int j=0;j<n-1;j++)
    {
    for(int i=0;i<n-1;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-1;i++)
    {
    System.out.print(ar[i]+" ");
    }
    System.out.println("\nEnter the Number");
    ar[n-1]=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("New Sorted array ");
    for (int i=0;i<n;i++)
    {
    System.out.print(ar[i]+" ");
    }
    }
    }

    ReplyDelete
  3. import java.util.Scanner;
    class A
    {
    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 i,pos,no;
    int arr[]=new int[n];
    System.out.println("Enter the value of array");
    for(i=0;in)
    System.out.println("out of range");
    else
    System.out.println("Enter the value");
    no=obj.nextInt();
    --pos;
    for(i=5;i>=0;i--)
    {
    arr[i+1]=arr[i];
    }
    arr[pos]=no;
    System.out.println("New array is");
    for(i=0;i<n;i++)
    {
    System.out.println(arr[i]);
    }
    }
    }

    ReplyDelete
  4. import java.util.Scanner;

    class Test{
    public static void main(String a[]){
    int ar[]=new int[100];
    int i,k,temp,number,new_number;

    System.out.print("Enter the number of elements: ");
    Scanner o=new Scanner(System.in);
    number=o.nextInt();
    System.out.println("Now enter the values of array: ");
    for(i=0;iar[i+1]){
    ar[i]+=ar[i+1];
    ar[i+1]=ar[i]-ar[i+1];
    ar[i]-=ar[i+1];
    }
    }
    }
    System.out.println("The sorted array is: ");
    for(k=0;kar[k]&&new_number<ar[k+1]){
    temp=ar[k+1];
    ar[k+1]=new_number;
    for(i=k+2;i<number+1;i++){
    temp+=ar[i];
    ar[i]=temp-ar[i];
    temp-=ar[i];
    }
    break;
    }
    }
    System.out.println("The final sorted array is: ");
    for(k=0;k<number+1;k++)
    System.out.print("\t"+ar[k]);
    }
    }

    ReplyDelete
  5. import java.util.Scanner;
    class insstele {

    public static void main(String args[])
    {
    int temp;
    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+1]; // we have made an array of n+1 because we have to insert one more element here
    System.out.println("Enter elements in array");
    for (int i=0;i<n-1;i++) // here we are entering one element less than array size
    {
    ar[i]=scan.nextInt();
    }
    for(int i=0;i<n-1;i++)
    {
    for(int j=0;j<n-1;j++)
    {
    if(ar[i]<ar[j])
    {
    temp=ar[i];
    ar[i]=ar[j];
    ar[j]=temp;
    }
    }
    }
    System.out.println("New array after sorting ");
    for (int i=0;i<n-1;i++)
    {
    System.out.print(ar[i]+" ");
    }
    System.out.println("\nEnter the element to be inserted");
    ar[n-1]=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("New Sorted array after insertion of new element : ");
    for (int i=0;i<n;i++)
    {
    System.out.print(ar[i]+" ");
    }
    }
    }

    OUTPUT:

    How many number you want to add
    5
    Enter elements in array
    12
    65
    4
    56
    New array after sorting
    4 12 56 65
    Enter the element to be inserted
    23
    New Sorted array after insertion of new element :
    4 12 23 56 65

    ReplyDelete
  6. import java.util.Scanner;
    class Insert{
    public static void main(String args[]){
    int n,i=0,j=0,temp=0;
    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 new element");
    ar[n+1]=scan.nextInt();

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




















    ReplyDelete
  7. import java.util.Scanner;
    class Sorted{
    public static void main(String a[]){
    int temp;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter the array size:");
    int n=scan.nextInt();
    n=n+1;
    int ar[]=new int[n];
    System.out.println("Enter the values of array:");
    for (int i=0;i<n-1;i++){
    ar[i]=scan.nextInt();
    }
    for(int j=0;j<n-1;j++){
    for(int i=0;i<n-1;i++){
    if(ar[j]<ar[i]){
    temp=ar[j];
    ar[j]=ar[i];
    ar[i]=temp;
    }
    }
    }
    System.out.println("Sorted array is:");
    for (int i=0;i<n-1;i++){
    System.out.print(ar[i]+" ");
    }
    System.out.println("Enter the number you want to add:");
    ar[n-1]=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("New Sorted array ");
    for (int i=0;i<n;i++){
    System.out.print(ar[i]+" ");
    }
    }
    }

    ReplyDelete