newb java help

Discussion in 'Mac Programming' started by cardude280, Oct 21, 2006.

  1. cardude280, Oct 21, 2006
    Last edited by a moderator: Aug 2, 2011

    cardude280 macrumors member

    Joined:
    Feb 26, 2006
    Location:
    West Virginia
    #1
    i'm working on learning java and i don't know what some of the compile errors mean. please help

    Code:
    Elvis.java:4: unexpected type
    required: variable
    found   : value
                    System.out.println("Elvis weighs " = weight);
                                       ^
    Elvis.java:8: unexpected type
    required: variable
    found   : value
                    System.out.println("Elvis now weighs " = weight);
                                       ^
    Elvis.java:11: unexpected type
    required: variable
    found   : value
                    System.out.println("Elvis now weighs " = weight);
                                       ^
    3 errors
    
     
  2. prostuff1 macrumors 65816

    prostuff1

    Joined:
    Jul 29, 2005
    Location:
    Don't step into the kawoosh...
    #2
    Code:
    Elvis.java:4: unexpected type
    required: variable
    found : value
    System.out.println("Elvis weighs " = weight);
    ^
    Elvis.java:8: unexpected type
    required: variable
    found : value
    System.out.println("Elvis now weighs " = weight);
    ^
    Elvis.java:11: unexpected type
    required: variable
    found : value
    System.out.println("Elvis now weighs " = weight);
    ^
    3 errors
    Well i can't exactly tell you what the errors mean but it looks like you might be confused on some stuff.

    If you are trying to print elvis's weight you statement should be somehting like
    Code:
    System.out.println("Elvis weighs " [B]+[/B] weight);
    the way you have it now you are trying to assign a number to a text string which does not quite work.
     
  3. cardude280 thread starter macrumors member

    Joined:
    Feb 26, 2006
    Location:
    West Virginia
  4. MrFrankly macrumors regular

    Joined:
    Jan 11, 2006
    #4
    Little addition to prostuff1's correct answer. About what the error messages mean.

    What you're not trying to do is assign a value to an other value. You can only assign values to variables, and they even have to be of the right type (string, int, double etc).

    So 'unexpected type' means that Java expected a variable in front of the assignment operator (=) instead of a value.
     
  5. surya.k, Aug 2, 2011
    Last edited by a moderator: Aug 2, 2011

    surya.k macrumors newbie

    Joined:
    Aug 2, 2011
    #5
    i have another similar problem here
    Code:
    System.out.println("Enter the roman numeral less than 50");
           String rom= in.readLine();
           rom=rom.trim();
           int l=rom.length();
           int units=0,tens=0;
           if(rom.charAt(0)="X" && rom.charAt(1)!="X" && rom.charAt(1)!="L")----it highlights this line and gives me an error saying unexpected type
           tens=1;
           else if(rom.charAt(0)="X"&&rom.charAt(1)=="X"&&rom.charAt(2)!="X")
           tens=2;
           else if(rom.charAt(0)="X"&&rom.charAt(1)=="X"&&rom.charAt(2)=="X")
           tens=3;
           else if(rom.charAt(0)="X"&&rom.charAt(1)=="L"&&rom.charAt(1)!="X")
           tens=4;
           else if(rom.charAt(0)="L")
           tens=5;
           else
           tens=0;
    
    what should i do?
    please help
     
  6. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #6
    Not necro ancient threads to ask a bearly related question.

    You have two additional problems. You're using = instead of ==. And charAt() returns a char not a String, yet you're using String instead of chars on the right-hand side of your operators. In short your using "a" instead of 'a'.
     

Share This Page