Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


pandu
java basic
1 Answer(s)      3 years and 11 months ago
Posted in : Java Beginners


java program for finding LCM and HCF


Advertisement
View Answers

January 20, 2011 at 4:02 PM


Hello, Code is below:

public class MathsDemo {

public static void main(String[] args) {

    MathsDemo demo = new MathsDemo();
    System.out.println("H.C.F./G.C.D.: " + demo.gcd(12, 16));
    System.out.println("L.C.M.: " + demo.lcm(12, 16));

}

int lcm(int a, int b) {
    return (a * b / gcd(a, b));
}

int gcd(int a, int b) {

    if (b > a) {
    a = a + b;
    b = a - b;
    a = a - b;
    }
    if (a != 0 && b != 0)
    return gcd(b, a % b);
    return a;

}

}

I think so this code might help you. :-) Anuj Kumar (Knapster)



Related Tutorials/Questions & Answers:
java basic
java basic  Java Basics tutorials
java basic
java basic  java program for finding LCM and HCF
Advertisements
Java basic
Java basic  How can I Use Eclipse to create a project and write a hello world java application
java basic
java basic  write java program to evaluate 1+x^2+x^3+x^4+............+x^n
java basic
java basic  i need to give a hexadecimal input (0x71014802 and 0x8c2a0000) and want to get a MIPS instruction code(assembly level lang.):the output is not a matter... i want to create a package and then input converted converted
basic java - Java Beginners
basic java  oops concept in java ?  Hi Friend, Please visit the following links: http://www.roseindia.net/java/beginners/oop-in-java.shtml http://www.roseindia.net/java/learn-java-in-a-day/oops.shtml Thanks
Basic Java Tutorial
Basic Java Tutorial  Hi, Where is the url of Basic Java Tutorials on roseindia.net? Thanks   Hi, You can Learn Java in a Day also? Thanks
java and visual basic
java and visual basic  Hello, Please how does java and visual basic interact or talk
Java basic question...
Java basic question...   Design a Java Application project...), emp_desig as String (To hold designation of the employee) and basic as Integer (To hold the basic salary of the employee). (iii) Define and declare a method
BASIC Java - Java Tutorials
Basic Java Syntax This tutorial guide you about the basic syntax of the java... of the java which is applicable to all java program : Case Sensitive Java Java... letter and lover case. For example, case and Case are different words in java
java core basic problem
java core basic problem  my question is: write a program that illustrates interface inheritance. interface P is extended by P1 and P2. interface... methode. class Q impliments P12 Instantiate Q and invoke each of its methods.Each
java core basic problem
java core basic problem  my question is: write a program that illustrates interface inheritance. interface P is extended by P1 and P2. interface... methode. class Q impliments P12 Instantiate Q and invoke each of its methods.Each
Basic problem for Java experts
Basic problem for Java experts  This assignment will test your knowledge of Arrays Array searching Array sorting Array processing Specification An athletics club require a simple statistical analysis program for analysing lap
Basic on J2ee - Java Beginners
Basic on J2ee  J2EE is a platform that helps us to develop and deploy enterprise application.It follows the component based architecure. So, it means that an application is developed in components in order to acheive reusability
top 20 basic programm of java
top 20 basic programm of java  what is the top 20 rule to learn the basic of java.   Learn Java through the following links: http://www.roseindia.net/java/ http://www.roseindia.net/java/beginners/index.shtml
Core java Basic
Core java Basic  How to compile a program using the package statement at the first line.Do I have to create a a Seperate Folder with the name of the package in my directory.Please tell me the steps
java basic - Development process
java basic  Hi, I write a program for printing string n no of times.i gave string in console.if i gave '&' or '|' or '>' or '<'.so i want... for solving the problem and visit to : http://www.roseindia.net/java/beginners
Java Basic - Applet
Java Basic  My Applet Programs are Compiling as well as Running properly. But when I close the Applet window I am getting an Error Message as: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException and also 10
basic
basic  thank you sir for your nice reply . ......sir my next que, if java program is modified,if the program is compiled & executed without saving it again,its previous execution takes place,why
Java Basic Tutorial for Beginners
Java Basic Tutorial for Beginners - Learn how to setup-development environment and write Java programs This tutorial will get you started with the Java... in Java who wants to get started with Java. After completing these tutorial you
Basic Java programming for Beginners
Basic Java programming for Beginners helps them to learn the fundamentals... programming. Basic Java tutorials of Roseindia help all those by giving them... the lectures and it will step-by-step take you from basic to advance level of Java
basic html
basic html  what is the difference between html4 and html5
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........  code for a simple java program which performs basic arithmetic operation addition,subtraction
basic program
basic program  hii actully i am goin for technical interview on java as fresher so please tell me what these two basic lines means : public static void main(String arg) and System.out.print(); please give me meaning of each
Basic Java Language Elements
Basic Java Language Elements       Java keyboards There are few keywords in Java programming... in the program.   Java Comments To comprehend any programming language
basic question
basic question  how we create a new table with the same structure and data of another table
basic doubts
basic doubts  can i write two beans within a same xml file..? Also can i write two xml files within a same package
A basic program
A basic program  Write a program that will print out the first 10 numbers, their squares and their cubes. Write a program that displays the first 100 terms of the triangular sequence. This is the sequence that goes
basic function of computer system
basic function of computer system  What is the basic function of computer system
Java 7 Language Fundamentals
This tutorial describes basic language features of Java 7
Advertisements
 

 

 

DMCA.com