Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do I connect 2 method headers to make it recursive???

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Thanked 0 Times in 0 Posts

    Default How do I connect 2 method headers to make it recursive???

    When my main method asks for a number, I want that number to be the value of printArray(int a). So the number I enter will run off the script that the printArray method has.

    A good website example would be nice. I keeping getting the n! = n * (n-1)! type of results but that's not exactly the type of recursion i am looking for.

     import java.util.*;
    public class InputLoop 
        public static int printArray(int a)
            if (a < 20 || a > 80) 
            else if (a >= 20 && a <= 80) 
            return a;
        public static void main(String[] args) 
            Scanner number = new Scanner(System.in);
            System.out.println("Enter a number between 20 and 80");
            int a = number.nextInt();

  2. #2
    Junior Member
    Join Date
    Nov 2011
    Thanked 1 Time in 1 Post

    Default Re: How do I connect 2 method headers to make it recursive???

    From my understanding of the question you want to read in a number between 20 and 80 and print out all integers between that number and 80.

    -Your computer only executes code that is in the main method so unless you make a reference to the method printArray[] it will never execute that code.
    -It would be possible to write this program recursively but it isn't necessary a simple while loop will do. However if you really want to do it recursively you will need to learn about recursion first.

    This book: Javanotes 6.0 -- Title Page will give you the basics of recursion.

    If you need any more help just ask.

Similar Threads

  1. Difficulty with method headers.
    By tripline in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 30th, 2011, 10:58 AM
  2. [SOLVED] StackOverflowError with recursive method
    By samfin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 2nd, 2010, 04:05 PM
  3. [SOLVED] Anyone bored and want to make a method for me?
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: October 8th, 2010, 01:36 PM
  4. Help, Want to make a BASIC min value Method with Generics
    By Iglesias in forum Collections and Generics
    Replies: 6
    Last Post: September 12th, 2010, 10:16 PM
  5. Method for legal moves in connect four.
    By mandar9589 in forum Algorithms & Recursion
    Replies: 3
    Last Post: December 27th, 2009, 05:28 PM