为什么调用func(str2)后Scanner(System.in)输入的字符串“🍷Hello”打印错误?
java代码如下:
package test;
import java.util.Scanner;
public class TestCodePoint
{
private static void func(String str)
{
System.out.println("after: " + str);
}
public static void main(String[] args)
{
String str = "🍷Hello";
System.out.println("before: " + str);
func(str);
System.out.print("Please input a string: ");
Scanner sc = new Scanner(System.in);
String str2 = sc.next();
System.out.println("str2_before: " + str);
func(str2);
}
}
执行结果为:
before: 🍷Hello
after: 🍷Hello
Please input a string: 🍷Hello (Here is the paste input)
str2_before: 🍷Hello
after: ��Hello
为什么最后一个输出的是“��Hello”而不是“🍷Hello”?