XII STD RECURSION WITHOUT SCANNER

XII STD RECURSION WITHOUT SCANNER

the recursive function gives a stack overflow error. I want to calculate the GDC ie the greatest Integer function for two input numbers. the code of my program is as follows and the error comes in the function gcd_func in the last condition giving stack overflow null. .I do not wish to use the scanner class Is there anything i can do to improve thiscode?

import java.io.*; public class reursion { public void main()throws IOException {BufferedReader stdin= new BufferedReader (new InputStreamReader( System.in)); System.out.println("Input two nos"); int a =Integer.parseInt(stdin.readLine()); int b =Integer.parseInt(stdin.readLine()); int gcd=1; int i=2; int p= gcd_func(a,b,gcd,i); System.out.println( "GCD+ +"+p); } int gcd_func(int a, int b, int gcd, int i) { if((a==1)||(b==1)) { return(gcd); } else if((a%i==0)&&(b%i==0)) { gcd=gcd*i; a=a/i; b=b/i; i++; return( gcd_func(a,b,gcd,i)); } else

    {   i++;
        return( gcd_func(a, b, gcd, i));
    }

}

}
View Answers

July 28, 2011 at 10:15 AM

import java.util.*;

class FINDGCD{
      public static int determineGCD(int a, int b) {
      if(b==0) 
      return a;
      else
      return determineGCD(b, a % b);
      }
      public static void main(String[] args)throws Exception {
                FINDGCD cal = new FINDGCD();
                Scanner input=new Scanner(System.in);
                System.out.println("Enter first number: ");
                int num1=input.nextInt();
                System.out.println("Enter second number: ");
                int num2=input.nextInt();
                int hcf = cal.determineGCD(num1, num2);
                System.out.println("GCD of two numbers= "+hcf);
        }
}









Related Tutorials/Questions & Answers:
XII STD RECURSION WITHOUT SCANNER
XII STD RECURSION WITHOUT SCANNER  the recursive function gives a stack overflow error. I want to calculate the GDC ie the greatest Integer function... not wish to use the scanner class Is there anything i can do to improve
without scanner
without scanner  a company need a system to store the data about the employees , the number of employees is dynamic , you need to store the following... and class and didn't use the scanner .   Hi Friend,ADS_TO_REPLACE_1
Advertisements
can we use scanner class,class , object and methods to get output without using constructor ????
can we use scanner class,class , object and methods to get output without using constructor ????  im getting error here..i hav used scanner class... am i getting error here... can we get output using scanner class , object
Scanner
Scanner   Hi, I am facing a problem in the following code as what should be the while condition I should use in order to get the loop keep running...= "Celsius"; do { Scanner temp_ip= new Scanner(System.in
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
ModuleNotFoundError: No module named 'std'
ModuleNotFoundError: No module named 'std'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'std' How to remove the ModuleNotFoundError: No module named 'std' error
ModuleNotFoundError: No module named 'std'
ModuleNotFoundError: No module named 'std'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'std' How to remove the ModuleNotFoundError: No module named 'std' error
recursion
recursion program
recursion program  Hi this is my first java class, and i have been trying for hours to do this program. it is a recursion problem where the user will enter a continuous monthly investment, at a rate of 1% the program should say
ModuleNotFoundError: No module named 'recursion'
ModuleNotFoundError: No module named 'recursion'  Hi, My Python... 'recursion' How to remove the ModuleNotFoundError: No module named 'recursion' error? Thanks   Hi, In your python environment you
recursion numbers - Java Beginners
recursion numbers  I need to use recursion to test all values from 0 to 20 and see if they are contain in a 1-D array with values: 2,4,6,8,10,12,14,16,18,20. The results of all numbers from 0-20 will be printed
javascript recursion example
javascript recursion example   javascript recursion example   <html> <script> function factorial (n) { if(n==0) return(1); return (n * factorial (n-1) ); } document.write(factorial(5)); <
ModuleNotFoundError: No module named 'cyclotron-std'
ModuleNotFoundError: No module named 'cyclotron-std'  Hi, My... 'cyclotron-std' How to remove the ModuleNotFoundError: No module named 'cyclotron-std' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'cyclotron-std'
ModuleNotFoundError: No module named 'cyclotron-std'  Hi, My... 'cyclotron-std' How to remove the ModuleNotFoundError: No module named 'cyclotron-std' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'std-domain'
ModuleNotFoundError: No module named 'std-domain'  Hi, My Python... 'std-domain' How to remove the ModuleNotFoundError: No module named 'std... have to install padas library. You can install std-domain python
ModuleNotFoundError: No module named 'std-encode'
ModuleNotFoundError: No module named 'std-encode'  Hi, My Python... 'std-encode' How to remove the ModuleNotFoundError: No module named 'std... have to install padas library. You can install std-encode python
ModuleNotFoundError: No module named 'cyclotron-std'
ModuleNotFoundError: No module named 'cyclotron-std'  Hi, My... 'cyclotron-std' How to remove the ModuleNotFoundError: No module named 'cyclotron-std' error? Thanks   Hi, In your python
recursion method - Ajax
recursion method  Can i ask for a program that input a lines in the diamond shape recursion method   Hi friend, Code for solving the problem : public class RecursiveDiamond { public RecursiveDiamond
Building a Binary Tree using std::map, std:set
Building a Binary Tree using std::map, std:set  Hi, can someone please explain to me how I can make use of std::map and/or std::set to create a simple binary tree? I do not seem to understand how these 2 containers can be used
ModuleNotFoundError: No module named 'dongjun_recursion'
ModuleNotFoundError: No module named 'dongjun_recursion'  Hi, My... named 'dongjun_recursion' How to remove the ModuleNotFoundError: No module named 'dongjun_recursion' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'hjc_recursion'
ModuleNotFoundError: No module named 'hjc_recursion'  Hi, My... 'hjc_recursion' How to remove the ModuleNotFoundError: No module named 'hjc_recursion' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-recursion'
ModuleNotFoundError: No module named 'python-recursion'  Hi, My... named 'python-recursion' How to remove the ModuleNotFoundError: No module named 'python-recursion' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'python-recursion'
ModuleNotFoundError: No module named 'python-recursion'  Hi, My... named 'python-recursion' How to remove the ModuleNotFoundError: No module named 'python-recursion' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'python-recursion'
ModuleNotFoundError: No module named 'python-recursion'  Hi, My... named 'python-recursion' How to remove the ModuleNotFoundError: No module named 'python-recursion' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'python-recursion'
ModuleNotFoundError: No module named 'python-recursion'  Hi, My... named 'python-recursion' How to remove the ModuleNotFoundError: No module named 'python-recursion' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'Recursion-abhi'
ModuleNotFoundError: No module named 'Recursion-abhi'  Hi, My... named 'Recursion-abhi' How to remove the ModuleNotFoundError: No module named 'Recursion-abhi' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'recursion-chintan'
ModuleNotFoundError: No module named 'recursion-chintan'  Hi, My... named 'recursion-chintan' How to remove the ModuleNotFoundError: No module named 'recursion-chintan' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'recursion-detect'
ModuleNotFoundError: No module named 'recursion-detect'  Hi, My... named 'recursion-detect' How to remove the ModuleNotFoundError: No module named 'recursion-detect' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'recursion-visualiser'
ModuleNotFoundError: No module named 'recursion-visualiser'  Hi...: No module named 'recursion-visualiser' How to remove the ModuleNotFoundError: No module named 'recursion-visualiser' error? Thanks   Hi
ModuleNotFoundError: No module named 'recursion_xxx'
ModuleNotFoundError: No module named 'recursion_xxx'  Hi, My... 'recursion_xxx' How to remove the ModuleNotFoundError: No module named 'recursion_xxx' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dongjun_recursion'
ModuleNotFoundError: No module named 'dongjun_recursion'  Hi, My... named 'dongjun_recursion' How to remove the ModuleNotFoundError: No module named 'dongjun_recursion' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'hjc_recursion'
ModuleNotFoundError: No module named 'hjc_recursion'  Hi, My... 'hjc_recursion' How to remove the ModuleNotFoundError: No module named 'hjc_recursion' error? Thanks   Hi, In your python
Recursion - Java Beginners
Recursion  HI!Can i ask for another recursion diamond,using recursive method and asking for how many lines should be inputed to create the diamond..., This is simple code of recursion code. public class RecursiveDemo { public static
Recursion - Java Beginners
Recursion  Create a method called, rangeMult, that uses recursion to multiply a range of array elements. The method takes the following arguments: an int array that contains the range of elements to be multiplied, an int
Scanner class
Scanner class  what have to do when an error occur about Scanner class.i code scanner sc=new Scanner(System.in); but it shows an error regarding this.   Use Scanner sc=new Scanner(System.in
ModuleNotFoundError: No module named 'sahir_py_std'
ModuleNotFoundError: No module named 'sahir_py_std'  Hi, My Python... 'sahir_py_std' How to remove the ModuleNotFoundError: No module named 'sahir_py_std' error? Thanks   Hi, In your python
Scanner class
Scanner class  import java.util.*; class Dd { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int... Scanner class was introduced in java 5
ModuleNotFoundError: No module named 'HS-recursion-List'
ModuleNotFoundError: No module named 'HS-recursion-List'  Hi, My... named 'HS-recursion-List' How to remove the ModuleNotFoundError: No module named 'HS-recursion-List' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'HS-recursion-List'
ModuleNotFoundError: No module named 'HS-recursion-List'  Hi, My... named 'HS-recursion-List' How to remove the ModuleNotFoundError: No module named 'HS-recursion-List' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'HS-recursion-List'
ModuleNotFoundError: No module named 'HS-recursion-List'  Hi, My... named 'HS-recursion-List' How to remove the ModuleNotFoundError: No module named 'HS-recursion-List' error? Thanks   Hi, In your
scanner program
scanner program  a news paper boy purchase 100 papers every day.he purchases papers at Rs.1.50 and sells at Rs.2.00 at each.any unsold news papers... his profit..using scanner
Scanner
Iteration without loop
Iteration without loop  Hi, Is there any way I can have a line of code iterate a number of times set by the user without having a while loop or any...[] args) { Scanner input=new Scanner(System.in
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion

Ads