Results 1 to 3 of 3
  1. #1
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default many variables on an if statement

    Hi everybody,
    i'm a java beginner (very, very beginner) who encountered a problem studying the language...

    here's a chunk of a small code that I used to try the if statement...

    Java Code:
         double primoNumero, secondoNumero, terzoNumero, quartoNumero, quintoNumero, somma;
    primoNumero = 0;
            secondoNumero = 0;
            terzoNumero = 0;
            quartoNumero = 0;
                    quintoNumero = 0;
       
           System.out.print("Inserisci al massimo 5 numeri ");
           Scanner numeri = new Scanner(System.in);
           
           if (secondoNumero == 0 && terzoNumero && quartoNumero == 0 && quintoNumero == 0)  {
            System.out.println("Hai inserito un solo numero!");
    }
    (please excuse me for the italian text...)

    but the compiler gave me an error message wich says: "bad operand types for binary operator '&&' first type: boolean, second type: double" for the "if" statement line...


    now, I have not declared any boolean variable and I can't figure out what's wrong here :(

    Thanks in advance
    Chri :)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: many variables on an if statement

    if (secondoNumero == 0 && terzoNumero && quartoNumero == 0 && quintoNumero == 0)

    All the other ones are '<variable> == 0', but you seem to have forgotten the '== 0' part for 'terzoNumero'.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default Re: many variables on an if statement

    Dear god I think I should take a break after this....thing!

    Anyway, thanks a lot, solved. xD

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2012, 04:27 PM
  2. help with variables please
    By arimaliz in forum New To Java
    Replies: 3
    Last Post: 03-22-2011, 04:30 PM
  3. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 05:48 PM
  4. Variables
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:44 PM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •