I'm dying here. I can't find out why my code isn't working. I get "illegal start of expression" in Blue J. It's on line 34 ( if((menuchoice = = 0) && (gender.equals("M"))) )

/**
 * Brandon
 * November 14, 2007
 * TDEE
 */
import java.util.Scanner;
public class TDEE
{
    public static void main(String[] args)
    {
        Scanner keyboardInput = new Scanner(System.in);
        
        System.out.print("Please enter your name: ");
        String name = keyboardInput.nextLine();
        System.out.print("Please enter your BMR: "); 
        int bmr = keyboardInput.nextInt();
        System.out.print("Please enter your Gender (M/F): ");
        String gender = keyboardInput.next();
    
        if((gender.equalsIgnoreCase("M") || gender.equalsIgnoreCase("F")))
        { 
            gender = gender.toUpperCase();
            
            System.out.println("Select your Activity Level");
            System.out.println ("[0] Resting (Sleeping, Reclining)");
            System.out.println("[1] Sedentary (Minimal Movement)");
            System.out.println("[2] Light (Sitting, Standing)");
            System.out.println("[3] Moderate (Light Manual Labor, Dancing, Riding Bike)");
            System.out.println("[4] Very Active (Team Sports, Hard Manual Labor)");
            System.out.println("[5] Extremely Active (Full-time Athlete, Heavy Manual Labor)"); 
            System.out.print("\nEnter the letter corresponding to your activity level: ");
            int menuchoice = keyboardInput.nextInt();
            
               if((menuchoice = = 0) && (gender.equals("M"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
               else if((menuchoice = = 0) && (gender.equals("F"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
               else if((menuchoice = = 1) && (gender.equals("M"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 1) && (gender.equals("F"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 2) && (gender.equals("M"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 2) && (gender.equals("F"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 3) && (gender.equals("M"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 3) && (gender.equals("F"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 4) && (gender.equals("M")))
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 4) && (gender.equals("F"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 5) && (gender.equals("M")))
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else if((menuchoice = = 5) && (gender.equals("F"))) 
               {
                   System.out.print(menuchoice);
                   System.out.println(gender);
                }
                else {
                    System.out.println("I'm sorry. You entered an invalid menu choice."); 
                }
        }
        else {
            System.out.println("I'm sorry. You entered an incorrect gender.");
        }
        
    }
}

Yes he does, and I believe that is his problem. Although it would have been nice to know which line "34" was, without having to count.

Yes he does, and I believe that is his problem. Although it would have been nice to know which line "34" was, without having to count.

Hmm I make it:

/**
* Brandon
* November 14, 2007
* TDEE
*/
import java.util.Scanner;
public class TDEE
{
  public static void main ( String[] args )
  {
    Scanner keyboardInput = new Scanner ( System.in );

    System.out.print ( "Please enter your name: " );
    String name = keyboardInput.nextLine();
    System.out.print ( "Please enter your BMR: " );
    int bmr = keyboardInput.nextInt();
    System.out.print ( "Please enter your Gender (M/F): " );
    String gender = keyboardInput.next();

    if ( ( gender.equalsIgnoreCase ( "M" ) || gender.equalsIgnoreCase ( "F" ) ) )
    {
      gender = gender.toUpperCase();

      System.out.println ( "Select your Activity Level" );
      System.out.println ( "[0] Resting (Sleeping, Reclining)" );
      System.out.println ( "[1] Sedentary (Minimal Movement)" );
      System.out.println ( "[2] Light (Sitting, Standing)" );
      System.out.println ( "[3] Moderate (Light Manual Labor, Dancing, Riding Bike)" );
      System.out.println ( "[4] Very Active (Team Sports, Hard Manual Labor)" );
      System.out.println ( "[5] Extremely Active (Full-time Athlete, Heavy Manual Labor)" );
      System.out.print ( "\nEnter the letter corresponding to your activity level: " );
      int menuchoice = keyboardInput.nextInt();

      if ( ( menuchoice = = 0 ) && ( gender.equals ( "M" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 0 ) && ( gender.equals ( "F" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 1 ) && ( gender.equals ( "M" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 1 ) && ( gender.equals ( "F" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 2 ) && ( gender.equals ( "M" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 2 ) && ( gender.equals ( "F" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 3 ) && ( gender.equals ( "M" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 3 ) && ( gender.equals ( "F" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 4 ) && ( gender.equals ( "M" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 4 ) && ( gender.equals ( "F" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 5 ) && ( gender.equals ( "M" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else if ( ( menuchoice = = 5 ) && ( gender.equals ( "F" ) ) )
      {
        System.out.print ( menuchoice );
        System.out.println ( gender );
      }
      else
      {
        System.out.println ( "I'm sorry. You entered an invalid menu choice." );
      }
    }
    else
    {
      System.out.println ( "I'm sorry. You entered an incorrect gender." );
    }

  }
}

Which would make sense since it appears to be the first instance where the = = is found.

It's not the = = because == has the same error. Any if statement there gives me the same error.

of course another thing to consider is the fact that your design is extremely bad.
Such long lists of if-else blocks is an almost certain sign of something that's done wrong, especially when (like you're doing) what happens inside those blocks is (almost) identical.

The assignment is to use if else blocks. And I haven't put the real stuff in the if-else blocks yet. I just did that to make sure it's working. But obviously its not. And how many times do I have to say it. The = = is NOT breaking the program (though it may be wrong). It's something else. In that case it would say illegal operator, not illegal start of an expression.

Kid, that "= =" IS the problem.
At least it's the problem that prevents the code you posted from compiling.

There are quite possibly more problems in the stuff you didn't post (if any), but that's certainly wrong.

And your idea that it would give you another error if it were wrong is wrong as well.

For the love of god, I had it the other way before and it didn't compile. I deleted the whole block and tried putting an if statement there and it didn't work.

...

This is f******* retarded. It did not work at school but it decides to work on the slightly-better computer at home. Fuck. You were right. Sorry.

No, = = didn't work at school or home. It was always wrong...

Next time listen to the experts, (i.e. us) and your problems will be solved more quickly.

This article has been dead for over six months. Start a new discussion instead.