import java.util.Scanner;
class CheckPassFail {
// Write a program called CheckPassFail which prints "PASS"
// if the int variable "mark" is more than or equal to 50;
// or prints "FAIL" otherwise.
static int k;
static String str;
public static void main(String arg[]) {
System.out.println("Enter the marks : ");
Scanner typein = new Scanner(System.in);
str = typein.nextLine();
typein.close(); //Scanner Close
k = Integer.parseInt(str);
if (k >= 50) {
System.out.println("PASS");
} else {
System.out.println("FAIL");
}
}
}
Следующий код дает одинаковый результат с вызовом close() на сканере или без него. [code]import java.util.Scanner;
class CheckPassFail { // Write a program called CheckPassFail which prints "PASS" // if the int variable "mark" is more than or equal to 50; // or prints "FAIL" otherwise. static int k; static String str;
public static void main(String arg[]) { System.out.println("Enter the marks : "); Scanner typein = new Scanner(System.in); str = typein.nextLine(); typein.close(); //Scanner Close k = Integer.parseInt(str); if (k >= 50) { System.out.println("PASS"); } else { System.out.println("FAIL"); } } } [/code] Здесь звонок обязателен или в других ситуациях?