0

I tried googling a lot for this error but they all are based on inappropriate arguments in the methods. But i have taken care of that and still this error is popping up :

Solution.java:52: error: cannot find symbol
        if(flagcheck(flag))
                     ^
symbol:   variable flag
location: class Solution
1 error

Here is my code : (check for the flagcheck function)

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");
        }
    }
  • 1
    Please use a proper indentation and brace style - the error will become obvious: there's an extra brace after `flag++`. – Tunaki Jul 31 '16 at 08:48
  • Oh Thanks a lot!! I just shifted to java after learning python so things are getting kind of messy – Karthik Kalidas Jul 31 '16 at 08:52

0 Answers0