google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Sunday, February 10, 2019

Java program for square root




Java program for square root:



import java.awt.*;
import java.awt.event.*;
import java.io.*;

class SqRoot extends Frame implements ActionListener
 {
   TextField t1,t2;
   Label l1,l2;
   Button b1,b2;

   SqRoot()
   {
    setVisible(true);
    setTitle("Special Purpose Claculator");
    setSize(400,400);
  
      l1=new Label("Input no.");
      l2=new Label("Output");
    
      t1=new TextField(10);
      t2=new TextField(10);

      b1=new Button("Calculate");
      b2=new Button("Clear");
      b1.addActionListener(this);
      b2.addActionListener(this);

     Panel p1=new Panel( );
     p1.setLayout(new GridLayout(2,2));

     p1.add(l1);
     p1.add(t1);
     p1.add(l2);
     p1.add(t2);





     Panel p2=new Panel( );
     p2.setLayout(new FlowLayout( ));

     p2.add(b1);
     p2.add(b2);

     Panel p3=new Panel();
     p3.setLayout(new GridLayout(2,1));
     p3.add(p1);
     p3.add(p2);
    add(p3);

   }
  public void actionPerformed(ActionEvent ae)
  {
    try
    {
      if(ae.getSource( )==b1)
      {
        int n=Integer.parseInt(t1.getText( ));
        double y;
        y= Math.sqrt(n);
        t2.setText(""+y);
      }
   else
      {
        t1.setText("");
        t2.setText("");
     }
   }
     catch(Exception e)
     {
       System.out.println("Error..."+e);
        dispose( );
      }

  }
   public static void main(String args[])
   {
     SqRoot s=new SqRoot( );
     s.validate( );
   }
}

Java program for hash table


import  java.util.*;
import java.lang.*;
import java.io.*;
class   hashtable
{
        static Hashtable<String,Double> stud=new Hashtable<String,Double>();
              public  static void main(String args[])
        {
                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));               
                do                {
                        System.out.println("****************MENU*****************");
                        System.out.println("1:ACCEPT RECORD\n2:DISPLAY ALL                      RECORDS\n3:FIND HIGHEST\n4:EXIT");
                        System.out.println("\nEnter your choice:");
                        int ch=0;
                        try
                        {
                                ch=Integer.parseInt(br.readLine());
                        }
                        catch(IOException e)
                        {
                                System.out.println(e);
                        }
                        switch(ch)
                        {
                                case 1:
                                        accept();
                                        break;
                                case 2:
                                        displayall();
                                        break;
                                case 3:
                                        fhigh();
                                        break;
                             




                                    case 4:
                                        System.exit(0);
                                default:
                                        System.out.println("You entered wrong choice! TRY AGAIN!!");
                                        break;
                         }
               }while(true);
      }
               public static void accept()
               {
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        String name="";
                        Double d=0.0;
                        System.out.println("Enter the name:");
                        try
                        {
                                name=br.readLine();
                                System.out.println("Enter the percentage:");
                                d=Double.parseDouble(br.readLine());
                        }
                        catch(IOException e)
                        {
                                System.out.println(e);
                        }

                        stud.put(name,d);
                }
                public static void displayall()
                {
                        Enumeration keys=stud.keys();
                        while(keys.hasMoreElements())
                        {
                                String key=(String)keys.nextElement();
                                System.out.println(key+"="+stud.get(key));
                        }
                }
                public static void fhigh()
                {
                      






                         Double max=0.0;
                        Enumeration keys=stud.keys();
                        while(keys.hasMoreElements())
                        {
                                String key=(String)keys.nextElement();
                                if(max<stud.get(key))
                                        max=stud.get(key);
                        }      
                        System.out.println("Highest Marks="+max);
                }
        
}
                       

*****************************************************************
OUTPUT
******************************************************************



Enter your choice:
1
Enter the name:
vijay
Enter the percentage:
71
****************MENU*****************
1:ACCEPT RECORD
2:DISPLAY ALL RECORDS
3:FIND HIGHEST
4:EXIT

Enter your choice:
1
Enter the name:
ajay
Enter the percentage:
77
****************MENU*****************
1:ACCEPT RECORD
2:DISPLAY ALL RECORDS
3:FIND HIGHEST
4:EXIT

Enter your choice:
1
Enter the name:
 atul
Enter the percentage:
81
****************MENU*****************
1:ACCEPT RECORD
2:DISPLAY ALL RECORDS
3:FIND HIGHEST
4:EXIT

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...