I'm new at programming and currently studying Java. I did a lot of research online and was not able to find my answer. I have to create a code with multiple methods that will return a value.
I know I can call the method by using variable()
however doing so will ask the user to enter the value again. I don't want to do that.
I attached a super simple example of what I'm looking to do. Thank you and hope my question was clear.
public class test
{
public static void welcomeMes(){
System.out.println("welcome message");
// does not return anything
}
public static int year(){
int year;
year = in.nextInt();
return year;
}
public static int month(){
int month;
month = in.nextInt();
return month;
}
public static void diplayData(){
System.out.printf ("month is " + month); // error cannot find symbol
System.out.printf ("year is " + year); // error cannot find symbol
}
public static void main (String [] args){
welcomeMes();
year();
month();
diplayData();
}
}