Home Answers Viewqa Java-Beginners XII STD RECURSION WITHOUT SCANNER

 
 


Ahsial Rick
XII STD RECURSION WITHOUT SCANNER
1 Answer(s)      a year and 10 months ago
Posted in : Java Beginners

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 Pages:
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, Whether
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
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
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
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
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
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
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
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
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)); <
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
scanner - Java Beginners
scanner   how to ask user to enter index in arry using scanner
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
scanner problem - Java Beginners
scanner problem  the program that enters sides of the triangle using scanner and outputs the area of triangle  Hi Friend, We... main(String []args){ Scanner scanner = new Scanner(System.in
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
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   ... { public static void main(String[] args) { Scanner input=new
Hp scanner - Java Beginners
Hp scanner  Hi guys, i would like to access hp scanner using java programme. could you refer me some useful information to proceed
how to reverse a string without changing its place
how to reverse a string without changing its place  how to reverse a string without changing its place   Hi Friend, Another way... void main(String[]args){ Scanner input=new Scanner(System.in
Java repeat string without using loops
Java repeat string without using loops In this section, you will learn how to repeat string without using for loops. The given example accepts the number of times and iterates the string to the number of times set by the user without
scanner Class Error - Java Beginners
scanner Class Error  Hello Sir ,When i run the program of Scanner Class ,there is Error Can not Resolve Symbol-Scanner how i can solve..., Scanner class is not provided. Check your version.It should work with java 1.5
Swap two numbers without using third variable
Swap two numbers without using third variable In this section we are going to swap two variables without using the third variable. For this, we have used input.nextInt() method of Scanner class for getting the integer type values
Generate array of random numbers without repetition
Generate array of random numbers without repetition In the previous section... created an application that will generate the array of random numbers without...[] = new int[10]; Integer in[] = new Integer[10]; Scanner input = new Scanner
Java file scanner
Java file scanner In this section, you will learn how to read a file using Scanner class. Description of code: J2SE5.0 provides some additional classes.... It also parses the primitive data. Scanner class gives a great deal of power
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
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 reverse string without using inbuilt functions
Java reverse string without using inbuilt functions In this tutorial, you will learn how to reverse string without using any inbuilt functions. Here, we...(reverseStringArray); } public static void main(String[] args) { Scanner input=new Scanner
Calculate factorial Using Recursion
Calculate factorial Using Recursion  ... by using recursion in jsp. To make a program on factorial, firstly it must be clear what is recursion. In a simple language we can define recursion
barcode scanner device usage in database application
barcode scanner device usage in database application  Am trying to design a supermarket inventory desktop database application however I can't seem to know how to use a barcode scanner device on my application can anyone put me
Multiply a range of array elements using Recursion
Multiply a range of array elements using Recursion In this section you will learn how to use recursion to multiply a range of array elements. For this we have created a method rangeMult() that takes three arguments: an int array
Pattern,Matcher,Formatter and Scanner classes
Pattern,Matcher,Formatter and Scanner classes This section Describes : 1... using the Formatter and Scanner classes and the PrintWriter.format/printf..., n) Formatted input The scanner API provides basic input
with out using scanner mul two matrices
with out using scanner mul two matrices  write a java program to multiply two matrices and print there result. note: don't use the scanner and the values is passed at run time....   import java.io.*; class
Find sum of series
Find sum of series This section illustrates you how to find the sum of n terms of the series using recursion. For this purpose, we have created a recursive...; } public static void main(String[] args) { Scanner input = new Scanner
input using scanner and add/sub/mul/div of a matrix
input using scanner and add/sub/mul/div of a matrix  hiiii...... performe matrix add/sub/mul/div using scanner
Summary - Scanner
Java: Summary - Scanner The main use of java.util.Scanner is to read values from System.in or a file. Many Scanner methods fit a simple pattern: nextXYZ..., but Scanner also supports BigDecimal, BigInteger, Float (returns float), Boolean (returns
Creating a File I/O using import scanner, io.* and text.*
Creating a File I/O using import scanner, io.* and text.*  open a file for reading and open another file for writing data. input file hours-int, hourly rate-double, name-string. output file name-string, hours-int, hourly rate
Action without a form.
Action without a form.  Can I have an Action without a form
Application without Interface Builder!!
Application without Interface Builder!!  Can we make our iphone application without Interface Builder???   hello, yes , it is possible to make an iphone application without interface builder.. we can also use only

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.