Thursday, May 25, 2017

Program in java to delete an element in an unsorted array

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package datastrucarraya;
import java.util.Scanner;
/**
 *
 * @author arpis
 */
public class deleteinsorted {
     public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
        System.out.println(" enter the number of elements in your array");
        int i =sc.nextInt();
        int ar[] = new int[i];
        // taking the input of the arrays
        System.out.println("enter the elements of the arrays");
        for(int j=0;j<(i);j++){
            ar[j]=sc.nextInt();
        }
          int l= i-1;
         System.out.println("enter the number to be deleted");
         int delnum=sc.nextInt();
         for(int j=0;j<(i);j++){
            if(ar[j]==delnum){
              ar[j]=(ar[j]-ar[j]);
             
                if(j==l){
                    System.out.println("new array with the deleted element is");
                    for(int ii=0;ii<(l);ii++){
                           System.out.println(ar[ii]);
        }
                }
                else{
                    for(int k=ar[j];k<l;k++){
                        ar[k]=ar[k+1];
                       
                    }
                    System.out.println("new array with the deleted element is");
                      for(int iii=0;iii<(l);iii++){
                           System.out.println(ar[iii]);
                }
               
            }
        }
        
}}
}

Program in java to insert a number in an unsorted array at any position

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package datastrucarraya;
/**
 *
 * @author arpis
 */
import java.util.Scanner;
public class insunsordedarray {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
        System.out.println(" enter the number of elements in your array");
        int i =sc.nextInt();
        int ar[] = new int[i+10];
        // taking the input of the arrays
        System.out.println("enter the elements of the arrays");
        for(int j=0;j<(i);j++){
            ar[j]=sc.nextInt();
        }
       
       
       System.out.println("enter the posotion to update");
      int pos =sc.nextInt();
     
       System.out.println("enter the new number "+pos);
       int newnum = sc.nextInt();
        if(ar[(pos-1)]==0&&pos<ar.length){
            System.out.println("array replaced with"+newnum);
          ar[pos-1]=newnum;
      }
        else{
            System.out.println("this position exceeds the array size");
        }
        if(ar[(pos-1)]!=0&&pos<ar.length){
            for(int k=(i-1);k>=pos-1;k--){
               ar[k+1]=ar[k];
            }
             ar[pos-1]=newnum;
        }
         for(int j=0;j<(i+10);j++){
             System.out.println(ar[j]);
        }
       
    }
   
}

Program in java to sort an array- linear search

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package datastrucarraya;
/**
 *
 * @author arpis
 */
import java.util.Scanner;
public class sortarray {
    public static void main(String[] args) {
        int i = 0;
        System.out.println("enter the size of the array");
        Scanner sc = new Scanner(System.in);
        i = sc.nextInt();
        int a[] = new int[i];
      
    
        System.out.println("enter the elements in the array");
        for (int j = 0; j < a.length; j++) {
            a[j] = sc.nextInt();
        }
        int las =0;
         las = a.length-1;
         for(int j =0;j<a.length;j++){
             for(int k=j+1; k<a.length;k++){
                 if(a[j]>a[k]){
                     int temp=0;
                     temp =a[j];
                     a[j]=a[k];
                     a[k]=temp;
                 }
             }
         }
        
        
         System.out.println("the sorted array is");
  for (int j = 0; j < i; j++) {
            System.out.println(a[j]);
        }
    }
}

program in java to search for a number in an unsorted array

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package datastrucarraya;
/**
 *
 * @author arpis
 */
import java.util.Scanner;
class a{
    public int al(int i){
         System.out.println("number found");
         int l =i+1;
        System.out.println("found at "+l);
       
         return i;
    }
}
public class searchunsortedarray{
    public static void main(String[] args) {
        int i = 0;
        boolean found= false;
        System.out.println("enter the limit of your array");
        Scanner sc = new Scanner(System.in);
      
         i = sc.nextInt();
        int a[] = new int[i];
        System.out.println("enter the elemets in your array");
        for (int j = 0; j < a.length; j++) {
            a[j] = sc.nextInt();
        }
 a sa= new a();
        System.out.println("enter the element you want to search for");
        int key;
        key = sc.nextInt();
        for (int j = 0; j < a.length; j++) {
                if(a[j]==key){
                    found= true;
                  sa.al(j);
                   
                }
                else{
                     found= false;
                }
        }
        if(found!=true){
         
            System.out.println("sorry! element not found");
           
           
           
        }
    }
}

Thursday, February 16, 2017

java program to Book a show at different movie theaters available


package javaclass;

import java.util.Scanner;

class BookMyshow {

    private String move_name;
    private String thetre_name;
   
    private int cost;

    void movies() {
       
        System.out.println("the movies available are");
        System.out.println(" 1.shreak -------- Rs.40 \n 2.stuart little - Rs.50 \n 3.game movie ---- Rs.60 \n 4.fun movie ----- Rs.70 ");
       
       
    }

}

class thea extends BookMyshow {
private int no_f_tickets;
    void th() {
        System.out.println("*******the theaters available are******* \n 1.karunya th \n 2.anna th");
        int k;
        int an;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("*******karunya theater*******");
            System.out.println("*******select a movie*******");
            System.out.println("movie available are \n 1.shreak \n 2.stuart little ");
            Scanner a = new Scanner(System.in);
            int o = a.nextInt();
            if (o == 1) {
                System.out.println("shreak movie @ kaurnya theater");
                System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=40*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- karunya theater");
                    System.out.println("movie --------------------- shreak");
                    System.out.println("cost ---------------------- Rs."+amount);
                    System.out.println("******************************************************");
                }

            }
            if (o == 2) {
                System.out.println("stuart little @karunya theater");
                 System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=50*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- karunya theater");
                    System.out.println("movie --------------------- staurt little");
                    System.out.println("cost ---------------------- Rs"+amount);
                    System.out.println("******************************************************");
                }

            }

        }
        if (n == 2) {
            System.out.println("*******anna theater*******");
            System.out.println("*******select a movie*******");
            System.out.println("movie available are \n 3.game movie \n 4.fun movie");
            Scanner b = new Scanner(System.in);
            int p = b.nextInt();
            Scanner a = new Scanner(System.in);
            int o = a.nextInt();
            if (o == 1) {
                System.out.println("game movie @ anna theater");
                 System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=60*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- anna theater");
                    System.out.println("movie --------------------- game movie");
                    System.out.println("cost ---------------------- Rs."+amount);
                    System.out.println("******************************************************");
                }

            }
            if (o == 2) {
                System.out.println("fun little @anna theater");
                 System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=70*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- anna theater");
                    System.out.println("movie --------------------- fun movie");
                    System.out.println("cost ---------------------- Rs."+amount);
                    System.out.println("******************************************************");
                }

            }
        }

    }
}

public class labfr {

    public static void main(String[] args) {
        BookMyshow ob = new BookMyshow();

        BookMyshow[] moviename = new BookMyshow[2];
        moviename[0] = ob;
        thea a = new thea();
        moviename[1] = a;

        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
        System.out.println("---------1.list of movies and their prices--------- \n-------2.acces and book tickets through theaters---");

        System.out.println("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        Scanner d = new Scanner(System.in);
        int h = d.nextInt();
        switch (h) {
            case 1: {
                ob.movies();
                break;
            }
            case 2: {
             
                a.th();
            }
        }

    }

}

Saturday, February 11, 2017

sorting and displaying largest and smallest number- using java

import java.util.*;

public class labfour {

    public static void main(String a[]) {
        int v[] = new int[5];
        System.out.println("enter any five elements of the array");
        Scanner sc = new Scanner(System.in);
        v[0] = sc.nextInt();
        Scanner l = new Scanner(System.in);
        v[1] = l.nextInt();
        Scanner s = new Scanner(System.in);
        v[2] = s.nextInt();
        Scanner c = new Scanner(System.in);
        v[3] = c.nextInt();
        Scanner g = new Scanner(System.in);
        v[4] = g.nextInt();

        System.out.println("sorting the above array");
        for (int i = 0; i < v.length; i++) {
            for (int j = i + 1; j < v.length; j++) {
                if (v[i] > v[j]) {
                    int temp = v[i];
                    v[i] = v[j];
                    v[j] = temp;

                }

            }
            System.out.println(v[i]);

        }

        System.out.println("the smallest number is " + v[0]);
        System.out.println("the largest number is " + v[4]);

    }

}
output:

movie ticket booking - using java program

import java.util.Scanner;

class BookMyshow {

    private String move_name;
    private String thetre_name;
 
    private int cost;

    void movies() {
     
        System.out.println("the movies available are");
        System.out.println(" 1.shreak -------- Rs.40 \n 2.stuart little - Rs.50 \n 3.game movie ---- Rs.60 \n 4.fun movie ----- Rs.70 ");
     
     
    }

}

class thea extends BookMyshow {
private int no_f_tickets;
    void th() {
        System.out.println("*******the theaters available are******* \n 1.karunya th \n 2.anna th");
        int k;
        int an;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("*******karunya theater*******");
            System.out.println("*******select a movie*******");
            System.out.println("movie available are \n 1.shreak \n 2.stuart little ");
            Scanner a = new Scanner(System.in);
            int o = a.nextInt();
            if (o == 1) {
                System.out.println("shreak movie @ kaurnya theater");
                System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=40*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- karunya theater");
                    System.out.println("movie --------------------- shreak");
                    System.out.println("cost ---------------------- Rs."+amount);
                    System.out.println("******************************************************");
                }

            }
            if (o == 2) {
                System.out.println("stuart little @karunya theater");
                 System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=50*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- karunya theater");
                    System.out.println("movie --------------------- staurt little");
                    System.out.println("cost ---------------------- Rs"+amount);
                    System.out.println("******************************************************");
                }

            }

        }
        if (n == 2) {
            System.out.println("*******anna theater*******");
            System.out.println("*******select a movie*******");
            System.out.println("movie available are \n 3.game movie \n 4.fun movie");
            Scanner b = new Scanner(System.in);
            int p = b.nextInt();
            Scanner a = new Scanner(System.in);
            int o = a.nextInt();
            if (o == 1) {
                System.out.println("game movie @ anna theater");
                 System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=60*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- anna theater");
                    System.out.println("movie --------------------- game movie");
                    System.out.println("cost ---------------------- Rs."+amount);
                    System.out.println("******************************************************");
                }

            }
            if (o == 2) {
                System.out.println("fun little @anna theater");
                 System.out.println("enter the number of tickets to be booked");
                Scanner j = new Scanner(System.in);
                int r = j.nextInt();
                int left= no_f_tickets-r;
                int amount=70*r;
                System.out.println("to continue to book for this movie prees 1");
                Scanner d = new Scanner(System.in);
                int h = d.nextInt();
                System.out.println("\n\n\n");
                if (h == 1) {
                    System.out.println("******************************************************");
                    System.out.println("theater ------------------- anna theater");
                    System.out.println("movie --------------------- fun movie");
                    System.out.println("cost ---------------------- Rs."+amount);
                    System.out.println("******************************************************");
                }

            }
        }

    }
}

public class labfr {

    public static void main(String[] args) {
        BookMyshow ob = new BookMyshow();

        BookMyshow[] moviename = new BookMyshow[2];
        moviename[0] = ob;
        thea a = new thea();
        moviename[1] = a;

        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
        System.out.println("---------1.list of movies and their prices--------- \n-------2.acces and book tickets through theaters---");

        System.out.println("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        Scanner d = new Scanner(System.in);
        int h = d.nextInt();
        switch (h) {
            case 1: {
                ob.movies();
                break;
            }
            case 2: {
             
                a.th();
            }
        }

    }

}


output:

Friday, February 10, 2017

java program to print perfect numbers between two limits the {min,max}={1,50}.


public class perfect {

public static void main(String[] args) {
int n = 1;
System.out.println("*****program to find d num of perfect num's b/w 2 limits****** \n ");
for (int i = 1; i <= 50; i++) {
int sum = 0;
for (n = 1; n < i; n++) {
if (i % n == 0) {
sum = sum + n;
}
}
if(sum==i)
System.out.println(i);
}
}
}