Java Tutorial

 
 
 
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sp10.bsb.pkg013;

import java.util.*;
import java.util.Scanner;
/**
 *
 * @author Hira
 */
public class SP10BSB013 {
      static  List<Integer> l=new ArrayList<Integer>();
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
     boolean y=true;  
     do{   
         System.out.println(\"Enter 1 to add a no.(non zero) in list\\n2 to edit no.\\n3 to search\");
         System.out.println(\"4 to delete\\n5 to check total no.\\n6 to print list\\n7 to exit\");
         System.out.println(\"enter your choice\");
         int choice=in.nextInt();
         switch(choice)
         {
            case 1:
                insert();
                break;
            case 2:
                edit();
                break;
            case 3:
                search();
                break;
            case 4:
                delete();
                break;
            case 5:
                total();
                break;
            case 6:
                print();
                break;
            case 7:
                toexit();
                break;
            default:
                System.out.println(\"bad input\");
                break;
        }
        System.out.println(\"want to process more? y/n\");
        String x=in.next();
        char ch=x.charAt(0); 
        if( ch==\'n\')
            y=false;
    }
    while(y!=false);

    }

    //*************************************************************************************

   static public void insert(){


       Scanner in=new Scanner(System.in);

        boolean y=true;
       do{
            System.out.println(\"enter no to add in list\");
            int num=in.nextInt();
            if(num==0)
                System.out.println(\"0 is not alowed\");
            else
                l.add(num);
            System.out.println(\"want to insert more?y/n\");
            String x=in.next();
            char ch=x.charAt(0);
            if( ch==\'n\')
                y=false;
         }
       while(y!=false); 
   }

  //*************************************************************************************8 

   static public void print(){


       if(l.isEmpty())
           System.out.println(\"list is empty \");
       else
            System.out.println(\"members of lists are:\");
            for(int i=0 ; i<l.size();i++)
                System.out.println(\"index \"+i+\" : \"+ l.get(i)+\" \");

   }

   //********************************************************************************


   static public void search(){

       //List<Integer> I=new ArrayList<Integer>();
       System.out.println(\"enter no to search\");
       Scanner in=new Scanner(System.in);

       int num=in.nextInt();
       for(int i=0;i<l.size();i++){
           if(l.get(i)==num)
                System.out.println(num+\" is  PRESENT at Index \"+i);
       }

       if(l.lastIndexOf(num)==-1)
               System.out.println(num+\" is NOT PRESENT\");
   }

   //*****************************************************************************8


   static public void edit(){


       Scanner in=new Scanner(System.in);
       int num1,num2;
       System.out.println(\"enter no you want to add\");
       num2=in.nextInt();
       if(num2==0)
             System.out.println(\"0 is not alowed\");
       else{
             try{
                System.out.println(\"enter position you want to edit\");
                num1=in.nextInt();
                l.set(num1, num2);
             }catch(IndexOutOfBoundsException e){
                    System.err.println(\"caught IndexOutOfBoundsException: specified position is empty \"+e.getMessage());
               }

          }
   }


    //************************************************************************************************8



    static public void delete(){


        Scanner in=new Scanner(System.in);
        System.out.println(\"enter position you want to delete\");
        int num=in.nextInt();
        l.remove(num);

    }


     //***********************************************************************88


    static public void total(){


        System.out.println(\"total no. in list are \"+ l.size());
    }

    //******************************************************************************


    static public void toexit(){

        System.exit(0);
    }
}

    Related Post:
  1. Program of creating a file using text fields in windows

  2. Game application in CORBA for which player will guess a number between 1 to 100, which will be compared to the random number generated by the class

  3. Do the following for the Array Insert the element in the array,delete an element from the array,search for a particular element Create multiple thread

  4. Program to print triangle of numbers

  5. Develop a CORBA based application for addition of two complex numbers and displaying the result on client side

  6. Develop a CORBA application that takes a string from client and returns whether it is palindrome

  7. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

  8. Program to declare and initialize Boolean variables and print them on the Standard Output Device

  9. Program to show an example of Polymorphism

  10. Program to show an example of using multiple classes in a program

  11. Write a program for restaurant

  12. Program to show an example of using a Static Nested Class

  13. Program to perform Merge Sort

  14. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  15. Program to show the use of Conditional OR Operator (||) in If Statements

  16. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  17. Program to declare, initialize and print a StringBuffer object

  18. Program to show an example of overloading constructors in a class to initialize its data members

  19. Program in CORBA which takes a long sentence from the client (at least 7 words), passes to the server, server separates out each word

  20. An applet program to display moving banner

 
 
Didn't find what you were looking for? Find more on Add,delete,Update in LISTS