java - The operator > is undefined for the argument type(s) boolean, double -


i new programmer, sorry if basic. have looked around website answer, find similar questions, none needed.

import java.util.scanner;  public class sortthreeintegers  {     public static void main (string[] args)          {         scanner input = new scanner(system.in);         scanner input2 = new scanner(system.in);         scanner input3 = new scanner(system.in);         system.out.println("enter first number: ");         system.out.println("enter second number: ");         system.out.println("enter third number: ");          double firstnumber = input.nextdouble();         double secondnumber = input2.nextdouble();         double thirdnumber = input3.nextdouble();          if (firstnumber > secondnumber > thirdnumber == true)          {             system.out.println(firstnumber + ", " + secondnumber + ", " + thirdnumber);         }         else if (firstnumber > thirdnumber > secondnumber == true)          {             system.out.println(firstnumber + ", " + thirdnumber + ", " + secondnumber);         }     } } 

note: in middle of me writing code, not finished this.

why getting error "the operator > undefined argument type(s) boolean, double"? again, sorry if simple.

if (firstnumber > secondnumber > thirdnumber == true) 

this invalid; want:

if (firstnumber > secondnumber && secondnumber > thirdnumber) 

the same goes else if condition.

you cannot chain comparisons in java can in, say, python. also, there never need == true in boolean expressions. after all, x == true x.


the error received makes sense, since expression being evaluated as:

(firstnumber > secondnumber) > thirdnumber 

now (firstnumber > secondnumber) boolean, cannot compared double (thirdnumber).


finally, looks you're trying output numbers in sorted order. why not sort them regularly, output result? also: don't use 3 different scanners! use same 1 3 times.

this mean sorting numbers:

double numbers[] = {firstnumber, secondnumber, thirdnumber}; arrays.sort(numbers); system.out.println(numbers[2] + ", " + numbers[1] + ", " + numbers[0]); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -