IDEA里面要设置UTF-8
nextInt前少个点
int w = new Scanner(System.in).nextInt();
解决了。
代码是没有什么问题的,你检查以下是不是没有导包import java.util.Scanner;