小编Dil*_*eep的帖子

是否必须关闭扫描仪?

使用下面的代码,我可以使用/不使用扫描仪关闭方法生成相同的输出.

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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java java.util.scanner

5
推荐指数
1
解决办法
250
查看次数

标签 统计

java ×1

java.util.scanner ×1