在大学期间,我将Java作为编程的一部分,而我已经完成的一些任务需要在家完成。我运行的是2017年款MacBook Pro,但在大学里我们有某种类型的HP台式机,发生的事情是,如果我在PC上的代码中使用了“£”符号,然后在Mac上运行了它们,编译会带来错误。
这是我使用符号的代码:
public void depositMoney()
{
int request = 0;
System.out.println("How much money do you wish to deposit into your RunshawPay account? Min: £2.50 / Max: £360.00");
System.out.print("£");
String depositRequest = inputScanner.nextLine();
try//type check
{
request = Integer.parseInt(depositRequest);
if (request <2.50 || request >360)
{
System.out.println("Number cannot be outside of range. [range]");
}
else
{
System.out.print("Amount is ok!");
}
}
catch (NumberFormatException ex)
{
System.out.println("Input needs to be integer. [type]");
}
}
这是我在终端上收到的错误:
ModularValidation2.java:60: error: unmappable character (0xA3) for encoding UTF-8
System.out.println("How much money do you wish to deposit into your RunshawPay account? Min: �2.50 / Max: �360.00");
ModularValidation2.java:60: error: unmappable character (0xA3) for encoding UTF-8
System.out.println("How much money do you wish to deposit into your RunshawPay account? Min: �2.50 / Max: �360.00");
ModularValidation2.java:61: error: unmappable character (0xA3) for encoding UTF-8
System.out.print("�");
我已经向我的导师展示了这个错误,他像我一样迷失了方向。我试图通过在编辑器中按键来替换字符(我正在使用Sublime)。有谁知道为什么发生这种情况以及可能的解决方案吗?非常感谢!