java basic

java basic

java program for finding LCM and HCF

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  write java program to evaluate 1+x^2+x^3+x^4+............+x^n
Java basic
Java basic  How can I Use Eclipse to create a project and write a hello world java application
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 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
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
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
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 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... in java, the first letter of class should be in the upper case. All the other
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
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
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
Is it possible to learn basic Java in a month?
Is it possible to learn basic Java in a month?  Hi, I am big fan... its right time to learn Java, web programming and make career in Software field. Is it possible to learn basic Java in a month? Thanks
Is it possible to learn basic Java in a month?
Is it possible to learn basic Java in a month?  Hi, I am big fan... its right time to learn Java, web programming and make career in Software field. Is it possible to learn basic Java in a month? Thanks
Is it possible to learn basic Java in a month?
Is it possible to learn basic Java in a month?  Hi, I am big fan... its right time to learn Java, web programming and make career in Software field. Is it possible to learn basic Java in a month? Thanks
Is it possible to learn basic Java in a month?
Is it possible to learn basic Java in a month?  Hi, I am big fan... its right time to learn Java, web programming and make career in Software field. Is it possible to learn basic Java in a month? Thanks
Is it possible to learn basic Java in a month?
Is it possible to learn basic Java in a month?  Hi, I am big fan... its right time to learn Java, web programming and make career in Software field. Is it possible to learn basic Java in a month? Thanks
Is it possible to learn basic Java in a month?
Is it possible to learn basic Java in a month?  Hi, I am big fan... its right time to learn Java, web programming and make career in Software field. Is it possible to learn basic Java in a month? Thanks
What are Basic Java Language Elements?
What are Basic Java Language Elements?  Hello, I have learned to setup Java and create first program. I want to know the Basic Java Language Elements. What are Basic Java Language Elements? Which is good tutorials of Java
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 of the language easily and quickly. Java is an Object Oriented Programming language... programming. Basic Java tutorials of Roseindia help all those by giving them
basic html
basic html  what is the difference between html4 and html5
Maven dependency for net.mingsoft - ms-basic version 2.1.13 is released. Learn to use ms-basic version 2.1.13 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.13 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 2.1.13 in Java...; net.mingsoft - ms-basic version 2.1.13 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 2.1.13.1 is released. Learn to use ms-basic version 2.1.13.1 in Maven based Java projects
this version ( net.mingsoft - ms-basic version 2.1.13.1 ) in their Java project... and includes  net.mingsoft - ms-basic version 2.1.13.1 java library in your project...Maven dependency for  net.mingsoft  - Version 2.1.13.1 of ms-basic
Maven dependency for net.mingsoft - ms-basic version 2.1.13.2 is released. Learn to use ms-basic version 2.1.13.2 in Maven based Java projects
this version ( net.mingsoft - ms-basic version 2.1.13.2 ) in their Java project... and includes  net.mingsoft - ms-basic version 2.1.13.2 java library in your project...Maven dependency for  net.mingsoft  - Version 2.1.13.2 of ms-basic
Maven dependency for net.mingsoft - ms-basic version 2.1.12 is released. Learn to use ms-basic version 2.1.12 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.12 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 2.1.12 in Java...; net.mingsoft - ms-basic version 2.1.12 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 2.1.11 is released. Learn to use ms-basic version 2.1.11 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.11 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 2.1.11 in Java...; net.mingsoft - ms-basic version 2.1.11 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 2.1.16 is released. Learn to use ms-basic version 2.1.16 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.16 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 2.1.16 in Java...; net.mingsoft - ms-basic version 2.1.16 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 2.1.15 is released. Learn to use ms-basic version 2.1.15 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.15 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 2.1.15 in Java...; net.mingsoft - ms-basic version 2.1.15 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 2.1.10 is released. Learn to use ms-basic version 2.1.10 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.10 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 2.1.10 in Java...; net.mingsoft - ms-basic version 2.1.10 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 1.0.25 is released. Learn to use ms-basic version 1.0.25 in Maven based Java projects
( net.mingsoft - ms-basic version 1.0.25 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 1.0.25 in Java...; net.mingsoft - ms-basic version 1.0.25 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 2.1.14.1 is released. Learn to use ms-basic version 2.1.14.1 in Maven based Java projects
this version ( net.mingsoft - ms-basic version 2.1.14.1 ) in their Java project... and includes  net.mingsoft - ms-basic version 2.1.14.1 java library in your project...Maven dependency for  net.mingsoft  - Version 2.1.14.1 of ms-basic
Maven dependency for net.mingsoft - ms-basic version 2.1.14 is released. Learn to use ms-basic version 2.1.14 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.14 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 2.1.14 in Java...; net.mingsoft - ms-basic version 2.1.14 java library in your project. ADS
Maven dependency for net.mingsoft - ms-basic version 2.1.8 is released. Learn to use ms-basic version 2.1.8 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.8 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.8 in Java... - ms-basic version 2.1.8 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.7 is released. Learn to use ms-basic version 2.1.7 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.7 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.7 in Java... - ms-basic version 2.1.7 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.6 is released. Learn to use ms-basic version 2.1.6 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.6 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.6 in Java... - ms-basic version 2.1.6 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.5 is released. Learn to use ms-basic version 2.1.5 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.5 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.5 in Java... - ms-basic version 2.1.5 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.4 is released. Learn to use ms-basic version 2.1.4 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.4 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.4 in Java... - ms-basic version 2.1.4 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.3 is released. Learn to use ms-basic version 2.1.3 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.3 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.3 in Java... - ms-basic version 2.1.3 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.2 is released. Learn to use ms-basic version 2.1.2 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.2 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.2 in Java... - ms-basic version 2.1.2 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.1 is released. Learn to use ms-basic version 2.1.1 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.1 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.1 in Java... - ms-basic version 2.1.1 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 2.1.0 is released. Learn to use ms-basic version 2.1.0 in Maven based Java projects
( net.mingsoft - ms-basic version 2.1.0 ) in their Java project if it is based... in project? Steps to use  net.mingsoft - ms-basic version 2.1.0 in Java... - ms-basic version 2.1.0 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for net.mingsoft - ms-basic version 1.0.38 is released. Learn to use ms-basic version 1.0.38 in Maven based Java projects
( net.mingsoft - ms-basic version 1.0.38 ) in their Java project... in project? Steps to use  net.mingsoft - ms-basic version 1.0.38 in Java...; net.mingsoft - ms-basic version 1.0.38 java library in your project. ADS

Ads