aspose file tools*
The moose likes Beginning Java and the fly likes operator && cannot be applied to boolean,int - error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "operator && cannot be applied to boolean,int - error " Watch "operator && cannot be applied to boolean,int - error " New topic
Author

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

Linda Selfridge
Greenhorn

Joined: Mar 26, 2011
Posts: 16
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

Joined: Jan 21, 2011
Posts: 637



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.

SCJP 6. Learning more now.
Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

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

Joined: Feb 13, 2011
Posts: 33

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 &&.


You're on a gravy train with biscuit wheels Roy.
Linda Selfridge
Greenhorn

Joined: Mar 26, 2011
Posts: 16
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

Joined: Mar 26, 2011
Posts: 16
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
Marshal

Joined: Mar 22, 2005
Posts: 42634
    
  65
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.


Ping & DNS - my free Android networking tools app
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 563
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!


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: operator && cannot be applied to boolean,int - error