编写一个应用Java应用程序,要求用户首先分别输入名字和姓,然后打印输出一个字符

2024-11-17 05:00:09
推荐回答(2个)
回答1:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestJava {

public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入姓:");
String str1=br.readLine();
System.out.println("请输入名:");
String str2=br.readLine();
System.out.println("您输入的姓名为:"+str1+str2);

}

}

回答2:

import java.util.Scanner;

public class Test {

public static void main(String[] args) {
Test t = new Test();
String name = t.f("input name");
String family_name = t.f("input family_name");
System.out.println(family_name+" "+ name);
}
public String f(String info) {
System.out.println(info);
Scanner keyBord = new Scanner(System.in);
String str = keyBord.next();
return str;
}
}