File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Boolean Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Boolean Problem" Watch "Boolean Problem" New topic

Boolean Problem

RH Gomez

Joined: Oct 15, 2005
Posts: 2
Hi all
I'm trying to write a program that gives the biggest of 3 numbers (integers) and this is the error I get "operator > cannot be applied to boolean, int" Could someone tell me what am I doing wrong? cuz a similar code works for just 2 numbers.
Here's the code

import acm.program.*;

public class ProgramaMayorDe3 extends DialogProgram {

public static void main(String[] args) {
new ProgramaMayorDe3().start();

public void run() {

int x;
int y;
int z;

x = this.readInt("Dame el primer numero:");
y = this.readInt("Dame el segundo numero:");
z = this.readInt("Dame el tercer numero:");

int r = this.mayor(x, y, z);

this.println("El mayor entre " + x + " , " + y + " y " + z + " es: " + r);

public int mayor(int a, int b, int c) {
if (a > b > c) {
return a;
} if (a < b > c) {
return b;
} else {
return c;

Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9058
a > b > c is not a java expression. You need something like


By the way, WillowR, welcome to JavaRanch. Please take a moment and adjust your display name to meet the JavaRanch Naming Policy.
You can change it here.

[ October 15, 2005: Message edited by: Marilyn de Queiroz ]

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
marc weber

Joined: Aug 31, 2004
Posts: 11343

The problem with (a > b > c) is that a > b evaluates to a boolean (true or false), and then you have a problem because you're trying to determine if this boolean is "greater than" c (which is an int). You can't compare booleans to ints.

Basically, you'll want to rewrite this to something like...

(a > b) && (b > c)

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Think for a minute how you'd solve this without a computer. If I gave you a written list of numbers just big enough that you couldn't spot the biggest one easily you might look at the first and say "that's the biggest so far", then look at the next and see if it's bigger, then the next. When you find a new "biggest so far" you might put your finger there to hold the place.

I'm thinking like a mean spirited teacher ... what if your instructor says "Now you've solved for three, do it for ten" how could you make the program handle more input numbers without getting longer and longer combinations of x > a && x > b ...

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
subject: Boolean Problem
It's not a secret anymore!