所以我在顶部有问题,但我想把所有问题都放在顶部,当我需要提问时,我可以使用定义为问题的变量将它们拉下来。然而,现在,代码从问题所在的位置询问问题,而不是使用变量“ask”并从 System.out.print(ask) 询问。关于如何让它做到这一点的任何想法?
import java.util.Scanner;
public class Greetings {
public static void main(String[] args) {
Scanner newscanner = new Scanner(System.in);
String ask = getString(newscanner, "Please enter your first name: ");
// String ask2 = getString(newscanner, "Please enter your last name: ");
// String ask3 = getString(newscanner, "Please enter your year of birth:
// ");
}
public static String getString(Scanner newscanner, String ask) {
System.out.print(ask);
String first = newscanner.next();
String firstletter = first.substring(0, 1).toUpperCase();
return firstletter;
}
}