Home>

I don't understand when studying Java, but create a getUserAge method with the return value and call it with the main method. > Ten years later, I'm 30!
I want to output and I am in trouble.

I would appreciate any solution.

Source code

public class Main {
static int getUserAge () {
int num = 20;
return num;
}
public static void main (String [] args) {
System.out.println ("10 years later" + getUserAge () + "I'm old!");
}
}

  • Answer # 1

    public class Main {
        static int getUserAge () {
            int num = 20;
            return num + 10;
        }
        public static void main (String [] args) {
            System.out.println ("10 years later" + getUserAge () + "I'm old!");
        }
    }

  • Answer # 2

    System.out.println ("I'm 30 years old in 10 years!");