Search code examples
javajgrasp

I am getting a Cannot find symbol error that I can't resolve


I am getting this error that to me looks like I am not calling the method correctly. I have reviewed the past answers here but none have specifically addressed my problem as far as I can see. This is for a class project. I realize my math in the method is most likely not correct yet but I need to get the rest working then deal with an incorrect out put. Thanks a lot!

Here is my code:

import java.util.*;

public class PrintOutNumbersInReverse {

    static Scanner console = new Scanner(System.in);

    public static void main(String[] args) {
        // Gather Number
        System.out.print("Enter a number between 2 and 10 digits long ");
        int num = console.nextInt();

        System.out.println("your number is: " + num);

        // call method
        System.out.println("Your number in reverse is: " + reverse);

    }

    public static int reverse(int num, int rNum) {
        rNum = 0;
        while (num != 0) {
            rNum = rNum + num % 10;
            num = num / 10;
        }
    }
}

And My error Message:

PrintOutNumbersInReverse.java:28: error: cannot find symbol System.out.println ("Your number in reverse is: " +reverse); ^ symbol: variable reverse location: class PrintOutNumbersInReverse 1 error


Solution

  • Change method implementation to:

    public static int reverse (int num)
    {
    
     int rNum = 0;
     ...
    
     return rNum;
    }
    

    and place, that is calling this method to:

    System.out.println ("Your number in reverse is: " +reverse(num));
    

    Then should be fine