I'm new to Java so I'm practicing with some simple code. I want to create some methods and use Scanner
for all of them, but I don't want to declare Scanner
every time I create other new methods.
So here is my code. Is this correct? Are there better ways to do this?
import java.util.*;
public class TripPlanner {
public static final Scanner input = new Scanner(System.in);
public static void main(String[] args) {
Greeting();
}
public static void Greeting() {
System.out.println("Welcome to Vacation Planner");
System.out.print("What is your name? ");
String name = input.nextLine();
System.out.print("Nice to meet you " + name +", where are you travelling to? ");
String place = input.nextLine();
System.out.println("Great! " + place + " sounds like a great trip" );
System.out.println("************");
System.out.println("\n");
}
}