从系统输入中放置 while 条件不起作用

Putting the while condition from system input is not working

main 方法中,我从 system.in 读取输入并将其传递给 while 条件。但它不起作用。每次取默认53例。想不出哪里错了。

如果我在 while 循环上方手动分配 int num = 15 而不是 int num = br.read()。它工作正常。

public class Parenthesis
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter number of test cases: ");
        int num = br.read();
        while(num > 0)
        {
            System.out.println(num-- + "Chances Left");
            String str = br.readLine();
            if(isParenthesis(str))
                System.out.println("Cool Rudra");
            else
                System.out.println("Poor Rudra");
        }
    }

    public static boolean isParenthesis(String str)
    {
        if(str == "Rudra")
            return true;
        else
            return false;
    }
}

下面使用

int num = Integer.parseInt(br.readLine()); 

而不是

int num = br.read();

从用户

获取int的另一种方式
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();