Saturday, September 21, 2013

Find LCM of two numbers using loop

Aim: To Find LCM of two numbers using loop

Syntax:

 /* LCM using loop
  *
  * by Aditya Sureka
  */
  //import the IO package
  import java.io.*;
  public class program15  //class name
  {
    public static void main(String args[])throws IOException ///main function
   {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     System.out.println("Enter the two nos.");
     //Accept the inputs from the user
     int big=Integer.parseInt(br.readLine());
     int small=Integer.parseInt(br.readLine());
     int rem=1;//Intialize Remainder =1
     while(rem!=0)//while remainder is not equal to 0
      {
        rem=big%small; //FInd the remainder
        if(rem!=0)//If the remainder is not equal to 0,proceed
         {
            big=small;
            small=rem;
          }
      }
      // Print the LCM
    System.out.println(small);
    }
  }



Hello Guys!!

This new blog is to provide tutorial to JAVA beginners who have gone through theory once. I won't get into the theory as you can get all those from other tutorials and websites. I will provide codes and explain them .That's it .Short and simple. If someone can contribute to any of my little projects I will be happy.I am providing tutorial for Android Application Development too , it will be on-line soon.


Mostly this blog will be used to share code , sample input output and help troubleshoot the learners.