我刚开始用Scala在学习曲线上奋斗。我通常通过实施前20个左右的欧拉问题来做这种事情。当我击中#4时,事情发生了翻天覆地的变化。
/*
A palindromic number reads the same both ways.
The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
*/
object Four
{
def main(args: Array[String])
{
println("start");
println("end");
}
}
虽然它可能不会向你跳出来,但注释中91到99之间的x实际上是一个unicode x,它被编码为D7。如果我将其更改为ASCII X,程序将按预期编译并运行。如果我保持原样,程序似乎运行,但没有输出。
从命令行运行
c:\projects\Euler>scalac -feature euler4.scala
error: IO error while decoding euler4.scala with UTF-8
Please try specifying another one using the -encoding option
one error found
对SO的一些研究建议指定编码
c:\projects\Euler>scalac -encoding UTF-8 -feature euler4.scala
error: IO error while decoding euler4.scala with UTF-8
Please try specifying another one using the -encoding option
one error found
我的配置是Windows 10 “欢迎使用Scala 2.12.1(Java HotSpot(TM)64位服务器VM,Java 1.8.0_121)。”