在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;
}
}
答案 0 :(得分:0)
使用以下
int num = Integer.parseInt(br.readLine());
而不是
int num = br.read();
答案 1 :(得分:0)
从用户
获取int
的另一种方法
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();