answersLogoWhite

0


Best Answer

for two positive integers:

public static int gcd(int i1, int i2) {

// using Euclid's algorithm

int a=i1, b=i2, temp;

while (b!=0) {

temp=b;

b=a%temp;

a=temp;

}

return a;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

simple program for recursion in java

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to find gcd using recursive method in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Differences between declaring a method and calling a method?

Declaring a method is when you code for what the method will perform. When you call a method, you are using the method you have written in another part of the program, (or inside the method if it is recursive).


How do you write a C program to find the GCD of two given integers using non recursive functions?

Use the following function: int gcd (int a, int b) { while (b != 0) { a %= b; a ^= b ^= a ^= b; } return a; } Note that a ^= b ^= a ^= b is an efficient method of swapping two values.


How to write java program without using main method?

Java program without mainWe need a main method for executing a program.But YES we can write a program without using main() method.TRICK 1 of 2 :: while writing applets in java we don't use main... we use init() method instead.TRICK 2 of 2 :: using 'static' we can write a program whic will execute successfully and output the desired message on screen. Here it is :: class Mohit{ static { System.out.println("This java program has run without the main method"); System.exit(0); } } -->save the program as Mohit.java to compile::javac Mohit.java (in command prompt) to run ::java Mohit(command prompt) output will be ::This java program has run without the main methodWhoa!!!!! we are done.;)


How do you write java program using two main method?

When you start your xxxx.class it will execute its 'public static void main (String args[])' method. Any other main methods won't be executed, only if your program explicitly calls them.


How do you write Square program using vb?

write a vb program to find the magic square

Related questions

Jntu 2-2 oops through java answers?

write a java program to find factorial using recursive and non recursive


Differences between declaring a method and calling a method?

Declaring a method is when you code for what the method will perform. When you call a method, you are using the method you have written in another part of the program, (or inside the method if it is recursive).


Write a c program to find GCD of two given integers by using both recursive n non recursive functions?

i love u darling


Write a program to find the product of two numbers using Halving and Doubling method?

i need this answer


Biggest of three nos using recursive method?

biggest3 (a,b,c) = biggest2 (a, biggest2 (b,c))


How do you write a C program to find the GCD of two given integers using non recursive functions?

Use the following function: int gcd (int a, int b) { while (b != 0) { a %= b; a ^= b ^= a ^= b; } return a; } Note that a ^= b ^= a ^= b is an efficient method of swapping two values.


How to write java program without using main method?

Java program without mainWe need a main method for executing a program.But YES we can write a program without using main() method.TRICK 1 of 2 :: while writing applets in java we don't use main... we use init() method instead.TRICK 2 of 2 :: using 'static' we can write a program whic will execute successfully and output the desired message on screen. Here it is :: class Mohit{ static { System.out.println("This java program has run without the main method"); System.exit(0); } } -->save the program as Mohit.java to compile::javac Mohit.java (in command prompt) to run ::java Mohit(command prompt) output will be ::This java program has run without the main methodWhoa!!!!! we are done.;)


What does recursive mean?

Recursive refers to using a rule or procedure that can be applied repeatedly.


How do you write java program using two main method?

When you start your xxxx.class it will execute its 'public static void main (String args[])' method. Any other main methods won't be executed, only if your program explicitly calls them.


Write a sample program using ASPNET explaining all the syntax and semantics of the program?

write a sample program using asp.net explaining all the syntax and semantics of the program


How do you write Square program using vb?

write a vb program to find the magic square


Write Client and server program in C language using UDP?

Write and run a client and a server program in C-language using UDP