Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
sc.close();
return i;
或
try(Scanner sc = new Scanner(System.in)) {
return sc.nextInt();
}
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
sc.close();
return i;
或
try(Scanner sc = new Scanner(System.in)) {
return sc.nextInt();
}