我尝试使用Google搜索这个错误,但它们都基于方法中不恰当的参数。但我已经处理了这个问题,但仍然出现了这个错误:
Solution.java:52: error: cannot find symbol
if(flagcheck(flag))
^
symbol: variable flag
location: class Solution
1 error
这是我的代码:(检查flagcheck函数)
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Scanner;
public class Solution {
//Checks if N is a power of 2 or not using binary operations
public static boolean powercheck(int N) {
if((N & (N - 1)) == 0)
return true;
else
return false;
}
//If N is a power of 2
public static void powertrue(int N) {
N=N-N/2;
}
//If N is not a power of 2
public static void powerfalse(int N) {
N-=Integer.highestOneBit(N-1);
}
//Which Player's turn it is
public static boolean flagcheck(int flag) {
if(flag%2==0)
return true;
else
return false;
}
//Main
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int i=1;i<=T;i++){
int N = in.nextInt();
int flag=1;
while(N>1){
if(powercheck(N))
powertrue(N);
else
powerfalse(N);
flag++;
}
}
if(flagcheck(flag))
System.out.println("Louise");
else
System.out.println("Richard");
}
}