Day 38: Find power, Common divisors, LCM in Looping Practices

Day 38: Find power, Common divisors, LCM in Looping Practices

Publish Date: May 6
1 0

Example 1 find power:

package demo_programs;

public class Find_power {
    private boolean find_prime(int no) {
        // TODO Auto-generated method stub
        int div = 2; 
        while(div<no)
        {
            if(Example 2 Find common divisorsno%div ==0)
            {
                return false; 
            }
            div=div+1; //div+=1; 
        }
        return true; 
    }}
Enter fullscreen mode Exit fullscreen mode

Example 2 Find common divisors

package demo_programs;

public class Find_CommonDivisors {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
      Find_CommonDivisors find=new Find_CommonDivisors();
      find.find_divisors(100, 120);
      }

    private void find_divisors(int no1, int no2) {
        // TODO Auto-generated method stub
        int div =2;
        int small=0;
        while (div<=small) {
            if( no1%div==0 && no2%div==0);
            System.out.println(div);
         div+=1;
        }
    }

}

Enter fullscreen mode Exit fullscreen mode

Example 3 LCM

package demo_programs;

public class LCM_01 {
     int no1 =3, no2 = 30;
     int big = no1>no2 ? no1:no2;{
        //  while (true){
            if (big%no1 == 0 && big%no2 == 0);
                  System.out.println("LCM is" + big);
           big+=1;}
}

Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment