public class b
{
 public double recDome(int x,int n)
  {
  
   if(n==0) return 1;
   if(n==1) return x;
   if(n>1)
   {
   double p=recDome(x,n/2);
   if(n%2==0) return p*p;
   return x*p*p;
   }
   return 1;
  }
  
public void print(int l)
{
System.out.print(l);
}
public static void main(String[] a)
{
b t=new b();
}
}
.......................................................................................................................
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Bases extends JFrame implements ActionListener
{
 JLabel Base,exponent,output;
 JTextField b,m,o;
 JButton ok,reset;
 Bases()
 {
 super("base");
 Container c=getContentPane();
 c.setLayout(new FlowLayout());
 Base=new JLabel("Base");
 b=new JTextField(9);
 
 exponent=new JLabel("exponent");
 m=new JTextField(9);
 
 output=new JLabel("output");
 o=new JTextField(9);
 
 ok=new JButton("OK");
 reset=new JButton("Reset");
 ok.addActionListener(this);
 reset.addActionListener(this);
 
 c.add(Base);
 c.add(b);
 
 c.add(exponent);
 c.add(m);
 
 c.add(output);
 c.add(o);
 c.add(ok);
 c.add(reset);
 setSize(500,300);
 setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
 JButton but=(JButton)e.getSource();
 if(but.getText()=="OK")
 {
  String B=b.getText();
  String E=m.getText();
  int x=Integer.parseInt(B);
  int n=Integer.parseInt(E);
  
  b t=new b();
  
  
  double l=t.recDome(x,n);
  o.setText(Double.toString(l));
 }
 else if(but.getText()==("Reset"))
 {
  b.setText("");
  m.setText("");
  o.setText("");
 }
 }
 public static void main(String[] a)
 {
  Bases b=new Bases();
  b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
}

No comments:
Post a Comment