statement « Boolean « Java Data Type Q&A

1. Using a boolean variable in while statement

A newbie question. I have the following piece of Java code:

 import acm.program.*;
 import java.awt.Color;

 public class ufo extends GraphicsProgram{

    private GRect ufo_ship;

2. C++ / Java: Toggle boolean statement?

Is there a short way to toggle a boolean? With integers we can do operations like this:

int i = 4;
i *= 4; // equals 16
/* Which is equivalent to */
i = i ...

3. Java value of if statements

In Java can I return a boolean value with the following:

public boolean areBothEven(int i, int j) {
    return (i%2 == 0 && j%2 == 0);
Or do I need ...

4. How to represent boolean expressions using if/else statement(s)? Is this right?

Is the expressions

!(a ==b)    a!=b equivalent?
i have yes here
!a && b     b &&!a
!a || b     b ||!a
no And how to ...

5. Java boolean if question

I am making a lottery program where I am asking if basically they would like a quick pick ticket. The numbers for their ticket of course would be random since ...

6. If statement always giving the same answer

import java.util.Scanner;

class Practice {

public static void main(String args[]) {

    System.out.println("Enter the number of treats you have:");
    Scanner treatsScanner = new Scanner(;
    int ...

7. Need to toggle a Boolean in a if else statement

Okay, I need to be able to call a method and toggle a boolean value so that the return is different every time I need to be able to call the ...

8. How does return type "boolean" affect print statement in a method ?

public class MonsterTestDrive{ public static void main(String [] args){ Monster [] ma = new Monster[3]; ma[0] = new Vampire(); ma[1] = new Dragon(); ma[2] = new Monster(); for(int x=0; x<3; x++){ ma[x].frighten(x); } } } class Monster{ boolean frighten(int d){ System.out.println("arrrgh"); return true; } } class Vampire extends Monster{ boolean frighten(int x){ System.out.println("a bite"); return false; } } class Dragon extends ...

9. boolean statements

Simply stating "I get a big time error" doesn't really help us help you. WHAT exactly is the error? Is it when you try to compile or when you run it? If it's a compiler error, what is the exact text of the error? If it's during run-time, what exactly is it doing wrong - what do you expect to happen, ...

10. How to use boolean statements to return "true" for certain cases?

Hello, I'm trying to write a method that will accept three integers as parameters and return true if one of the integers is the midpoint between the other two integers, and order does not matter. I'd appreciate some help on how I should use boolean statements in this; would I just have an if/else statement for each possible situation? ie. if((a+b)/2 ...

11. Return Statement and Boolean Help

Basically I am very new too java, I am an adult student and have been trying to understand return statements and Boolean expressions (used separately or together). The resources that I do have are just not clicking for me, so I was wondering if anyone could give me a crash course. Basically I under stand with Boolean the symbols such as ...

12. Question about If Statements and Boolean types - Help Greatly Appreciated

You should use a boolean or an enumated type for ***, not a String. That being said, compare strings with equals, not ==. You can also lose the extra parens -- && has lower priority, and you can also replace the if/then/else with something simpler. So [CODE] boolean bmiRange; if (g1="Male") && (bmi >= 19.1 && <= 25.8) { bmiRange=true } ...

13. boolean statements

14. boolean statements

15. Boolean if statement problems

17. if else statement --> (boolean)? expr1 : expr2 ;

Hey, I somewhere remember that if ... else ... can be written as booleanexpr?expr1true:expr2false ; but it doesn't work and the jvm gives " : expected as error" am i doing something wrong here? code : Vector lijst=new Vector(); for (int k=0;k