你好,我对简单方法有点困惑。我知道如何写“ Hello world”,但是我如何在外部使用2个参数:一个是“ hello”,另一个是名称。
预期输出为:Hello <name>
要使用2台扫描仪还是需要编写一个方法?
谢谢
答案 0 :(得分:2)
String str1, str2;
Scanner sc = new Scanner (System.in);
System.out.println ("1 Input");
str1 = sc.next ();
System.out.println ("1 Input");
str2 = sc.next ();
System.out.println (str1 + str2);
您的问题的答案
答案 1 :(得分:1)
import java.util.Scanner;
public class Main
{
public static void main (String[]args)
{
String str1, str2;
System.out.println ("1 Input");
str1 = input ();
System.out.println ("2 Input");
str1 = input ();
}
public static String input ()
{
Scanner sc = new Scanner (System.in);
return sc.next ();
}
}
像这样。