java编程 在main函数中输入两个字符串,将两个字符串连接起来并输出

求完整编程
2024-11-23 00:29:57
推荐回答(2个)
回答1:

import java.util.Scanner;

public class TestS {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入一串字符a");
String a = input.next();
System.out.println("请再输入一串字符b");
String b = input.next();
System.out.println("a和b的连接字符为:"+ a + b);
}

}

回答2:

import java.util.Scanner;

public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
String b = sc.nextLine();
System.out.println(a+b);
}
}

console:
abc
def
abcdef