大家好,我现在正在日本学习,这是我的问题:


我的代码:

class String4{
    public static void main(String[] args){
        String s="Hello.";
        char c = s.charAt(1);
        System.out.println(s +"の2文字目" + c + "です。");

        String s2 = s.toLowerCase();
        System.out.println(s +"を小文字にすると" + s2 + "です。");

        String s3 = s.toLowerCase();
        System.out.println(s +"を小文字にすると" + s3 + "です。");

        System.out.println("s2とHello.は等しい:" + s2.equals("Hello."));
        System.out.println("s2とHello.は等しい:" + s2.equalsIgnoreCase("Hello."));
    }
}

我的问题在CMD上运行时:

C:\Java>javac String4.java
String4.java:5: ???: ??????????????Cp1252?????????
System.out.println(s +"é╠éQò╢ÄÜû┌" + c + "é┼é╖?B");
                                              ^
String4.java:8: ???: ??????????????Cp1252?????????
System.out.println(s +"é≡?¼ò╢ÄÜé╔é╖éΘé╞" + s2 + "é┼é╖?B");
                         ^
String4.java:8: ???: ??????????????Cp1252?????????
System.out.println(s +"é≡?¼ò╢ÄÜé╔é╖éΘé╞" + s2 + "é┼é╖?B");
                                                     ^
String4.java:11: ???: ??????????????Cp1252?????????
System.out.println(s +"é≡?¼ò╢ÄÜé╔é╖éΘé╞" + s3 + "é┼é╖?B");
                         ^
String4.java:11: ???: ??????????????Cp1252?????????
System.out.println(s +"é≡?¼ò╢ÄÜé╔é╖éΘé╞" + s3 + "é┼é╖?B");
                                                     ^
String4.java:13: ???: ??????????????Cp1252?????????
System.out.println("s2é╞Hello.é═ôÖé╡éó?F" + s2.equals("Hello."));
                                      ^
String4.java:14: ???: ??????????????Cp1252?????????
System.out.println("s2é╞Hello.é═ôÖé╡éó?F" + s2.equalsIgnoreCase("Hello."));
                                      ^

最佳答案

您需要告诉编译器源文件位于UTF-8中:

javac -encoding UTF-8

10-06 09:20