Popular Posts

Thursday, December 9, 2010

X to the Power Y

class Power
{
    public static void main(String args[])
    {
        int n1,n2,i,power=1;
        n1=(int)(Math.random()*10);
        n2=(int)(Math.random()*10);
       
        System.out.println("First generated no. is="+n1);
        System.out.println("Second generated no. is="+n2);
       
        for(i=1;i<n2;n2++)
        {
            power*=n1;
            System.out.println("Power of number is:"+power);
        }
           
    }
}

Tuesday, October 19, 2010

OOPs programme

class Gcd
{
 public static void main(String args[])
 {
 
  int n1=(int)(Math.random()*100);
  int n2=(int)(Math.random()*100);
  System.out.println("First generated no. is"+n1);
  System.out.println("Second generated no. is"+n2);
  int max,min,i;
  if(n1>n2)
   {
     max=n1;
     min=n2;
   } 
  else
  {
   max=n2;
   min=n1;
  }
  System.out.println("Max is ="+max+" Min is ="+min);
 
  one: for(i=min;i>=1;i--)
  {
    if(max%i==0)
    {
     if(min%i==0)
     System.out.println("Output is "+i);
     else
     continue one;
   
    }
    if(max%i>0)
   
   
    System.out.println("GCD of no is =1");
   
  }
 } 
}