import java.util.Scanner;
public class userInput
{
public static void main(String[]args){
try{
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
int age = scanner.nextInt();
scanner.nextLine();
String text = scanner.nextLine();
System.out.println(name + "n" + age + "n" + text);
//scanner.close(); //it works here
}
finally{
scanner.close(); // does not work here"scanner cannot be resolvedJava(570425394)"
}
}
}
您必须在"try";,所以没关系,现在这是你的代码:
import java.util.Scanner;
public class userInput {
public static void main(String[]args) {
Scanner scanner = new Scanner(System.in);
try {
String name = scanner.nextLine();
int age = scanner.nextInt();
scanner.nextLine();
String text = scanner.nextLine();
System.out.println(name + "n" + age + "n" + text);
}
finally {
scanner.close();
}
}
}