Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Java operaton on boolean varibles

  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Java operaton on boolean varibles

    hello all i am finishing up a tic tac toe game but i have a question about Boolean vs int. my question is what do i do if i need to use symbols such as <>||=&& with boolean. here is a fragment of what i am working on to give you an idea of what im trying to do

    public boolean checkValid()
        {
            boolean col;
            boolean row;
        if(row<0||row>2)
            return true;
     
        }

    any help and suggestions are always appreciated


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: question about boolean varibles

    Boolean values can only hold true or false! So you cannot use<> operators, you can use the others though.

    Chris

  3. #3
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: question about boolean varibles

    ok so how would i go about creating that method using boolen.

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: question about boolean varibles

    Describe in words what you want to achieve, because I can't make any sense of that code lol

    Chris

  5. #5
    Member
    Join Date
    Apr 2009
    Posts
    31
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: question about boolean varibles

    ok this is what i am attempting to do. i need to add a method to check if a move is valid. for example if i put in 0,0 for x and the rperson playing o does the same thing i want to be able to tell them that move is invalid please pick again

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: question about boolean varibles

    You guys were up early this morning!!

    You could do it like this big_c:

    public class CheckMove {
     
        public static int row;
        public static boolean isValid;
     
        public static void CheckMyMove() {
     
            if (row < 0 || row > 2) {
                isValid = true;
            } else
                isValid = false;
     
        }
     
        public static void main(String[] args) {
     
            CheckMove cm = new CheckMove();
            cm.CheckMyMove();
     
            System.out.println(isValid);
     
        }
     
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Getting an error while altering a source code
    By marksquall in forum Collections and Generics
    Replies: 3
    Last Post: June 8th, 2009, 02:49 AM
  2. [SOLVED] Java exception "result already defined"
    By rptech in forum Object Oriented Programming
    Replies: 3
    Last Post: May 20th, 2009, 05:48 AM
  3. [SOLVED] How to narrow down the range of input in java?
    By big_c in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 20th, 2009, 11:38 AM
  4. How to show 2D array using combobox and radiobutton?
    By Broken in forum Loops & Control Statements
    Replies: 1
    Last Post: March 10th, 2009, 06:01 AM