Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java help -> boolean prob.

  • 31-10-2006 12:52pm
    #1
    Registered Users, Registered Users 2 Posts: 221 ✭✭


    Hi all !

    Been racking my head with this lilttle prob regrading declaring boolean varible ;

    public static boolean NotA, NotB, NotE, NotG, NotJ, NotL, NotO, NotR, NotV;
    //Flags to stop unessesary
    //Checks later on.

    NotA = NotB = NotE = NotG = NotJ = NotL = NotO = NotR = NotV = true;

    the compile error reads :
    .\LetterCheck.java:17: <identifier> expected
    NotA = NotB = NotE = NotG = NotJ = NotL = NotO = NotR = NotV = true;
    ^

    Any Help would be great thanks all


    -Elfman


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Try removing "static" from "public static boolean"


  • Registered Users, Registered Users 2 Posts: 221 ✭✭Elfman


    Thanks for quick reply didn't work got more errors.

    Recon it needs the static any other tips ? the whole code is attched if neone wants a look but i thinks it's this line si the problem.
    LetterCheck.txt


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    The problem is you are trying to put executable code into the class where no code block can run.

    If you really must do something like you have above it should be like this.
    public static boolean NotA, NotB, NotE, NotG, NotJ, NotL, NotO, NotR, NotV;
    //Flags to stop unessesary
    //Checks later on.
    static {
      NotA = NotB = NotE = NotG = NotJ = NotL = NotO = NotR = NotV = true;
    }
    

    Be warned that the static block runs once only. If they are instance variables you should init them in the constructor. Also be aware that the compiler basically stitches static execution blocks together in order of how they are written.

    However you should know that variables declared in the top level of the class are initialised to thier default values. In this case those booleans would automatically be false.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Elfman wrote:
    Thanks for quick reply didn't work got more errors.

    Post these new errors, they'll tell us more.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Just to prove it.. :)
    class Test { 
    
        static boolean a, b, c, d, e, f, g;
    
        static { 
            a = b = c = d = e = f = g = true;
        }
    
        public static void main(String[] args) { 
            System.out.println(g);
        }
    
    }
    


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    incidently the line below is also wrong...

    boolean True = 0;

    Apart from giving a variable name of True (which is terrible thing to do), booleans can only equate to true/false. Not to a value.

    You would also be better off getting rid of those comment lines at the end of if statements and just using proper indentation as it makes the code hard to read.


  • Registered Users, Registered Users 2 Posts: 221 ✭✭Elfman


    Oh yeah i get what your saying thanks a million i'l have to get a think over.

    thanks again

    -Elfman


Advertisement