提问人:Ken.Zhang 提问时间:5/16/2023 最后编辑:Ken.Zhang 更新时间:5/16/2023 访问量:44
为什么键盘输入的超级 Unicode 字符串在传递给方法后会发生变化?
Why does a keyboard-entered super Unicode string change after being passed to a method?
问:
为什么调用 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”?
答: 暂无答案
上一个:在字符串的特定位置查找字符
下一个:导致永恒循环迭代的扫描程序对象
评论
System.out.println("str2_before: " + str);
str
str2
str2
Scanner