Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

operator && cannot be applied to boolean,int - error

 
Linda Selfridge
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I am compling a program that is due tonight and I cannot get past these errors.....

I really need help on this one!



I keep getting the following errors....

Main.java:29: cannot find symbol
symbol : method nextint()
location: class java.util.Scanner
direction = keyboard.nextint();
^
Main.java:31: operator && cannot be applied to boolean,int
invalidEntry = (direction != left && Left && right && Right && down && Down && up && Up)
^
Main.java:32: cannot find symbol
symbol : variable counter
location: class Point
moves = ++counter;
^
Main.java:33: operator && cannot be applied to boolean,int
if (direction == left && Left) {
^
Main.java:34: cannot find symbol
symbol : method then(int)
location: class Point
then (x = x - 1);
^
Main.java:36: operator && cannot be applied to boolean,int
}else if (direction == right && Right) {
^
Main.java:37: cannot find symbol
symbol : method then(int)
location: class Point
then (x = x + 1);
^
Main.java:39: operator && cannot be applied to boolean,int
}else if (direction == down && Down) {
^
Main.java:40: cannot find symbol
symbol : method then(int)
location: class Point
then (y = y - 1);
^
Main.java:42: operator && cannot be applied to boolean,int
}else if (direction == up && Up) {
^
Main.java:43: cannot find symbol
symbol : method then(int)
location: class Point
then (y = y + 1);
^
Main.java:46: cannot find symbol
symbol : method then(int)
location: class Point
then ((invalidEntry));
^

Can anyone help me PLEASE!!! Desperate! I am having to use an online complier at the moment as I cannot access the remote one I am supposed to use for school.

Thanking everyone in advance!!!
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this tells you that there is no method called nextint(). Right, change it to nextInt();
When you have doubts about names, properties of a class look in oracle/sun docs online. This is just 1 error less, more remain.

PS : what is this code trying to do ? please describe it for ease of understanding.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Main.java:31: operator && cannot be applied to boolean,int
invalidEntry = (direction != left && Left && right && Right && down && Down && up && Up)
^

&& can only take boolean values ie, anything that can be true or false. Nothing else is allowed. Why are you giving it ints ?
M&&N means both M and N must evaluate to a boolean. eg. M can be (4>5) which is false. So the part after && is not evaluated. Since , && is a short-circuit operator(google it!).

PS : I would suggest that you refer your textbook for such theory. Which one do you use ?

 
Ernie Mcracken
Ranch Hand
Posts: 33
Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely you need to initiliaze your left and right ints, or your direction will never equal them, and you probably want to use the logical or operator || instead of &&.
 
Linda Selfridge
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My task is to write a program that calculates and displays a position of a point inside a square. Position of a point in the plane is specified by its coordinates, two numbers: x and y, often written as a pair (x,y). The position of the point is repeatedly changed by the user who enters a direction for the point to move: up, down, left or right. Then one of the point's coordinates, x or y, will increase or decrease by one unit. Initially the point lies at (0,0) which is the centre of a square whose sides are 8 units long. If the user enters 'l' (for left) or 'r' (for right) then the first coordinate, x, will decrement or increment, respectively. Similarly, the second coordinate, y, will increment or decrement if the user enters 'u' (for up) or 'd' (for down).

I am an external student and am using "Starting out with Java", trust me it is not my best subject.

I have done some more work and changed things around and now only have 8 errors but they are all on the same line!

 
Linda Selfridge
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is on line 48 and basically revolves around the try

Main.java:48: illegal character: \8220
System.out.print(“Invalid entry, try again”);
^
Main.java:48: ';' expected
System.out.print(“Invalid entry, try again”);
^
Main.java:48: not a statement
System.out.print(“Invalid entry, try again”);
^
Main.java:48: ';' expected
System.out.print(“Invalid entry, try again”);
^
Main.java:48: '{' expected
System.out.print(“Invalid entry, try again”);
^
Main.java:48: illegal character: \8221
System.out.print(“Invalid entry, try again”);
^
Main.java:48: not a statement
System.out.print(“Invalid entry, try again”);
^
Main.java:48: 'try' without 'catch' or 'finally'
System.out.print(“Invalid entry, try again”);
^
8 errors

Thanks
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The double quotes on that line don't look like regular double quotes but rather like fancy ones a word processor might use. Java does not recognize those.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:The double quotes on that line don't look like regular double quotes but rather like fancy ones a word processor might use. Java does not recognize those.

Good eyes!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic