Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cardude280

macrumors member
Original poster
Feb 26, 2006
88
0
West Virginia
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
 
Last edited by a moderator:

prostuff1

macrumors 65816
Jul 29, 2005
1,482
18
Don't step into the kawoosh...
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.
 

MrFrankly

macrumors regular
Jan 11, 2006
112
0
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.
 

surya.k

macrumors newbie
Aug 2, 2011
1
0
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
 
Last edited by a moderator:

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
what should i do?
please help

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'.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.