Wednesday, 15 May 2013

java - I'm getting an error with <= saying that it's an invalid AssignmentOperator + my code looks wack I think -



java - I'm getting an error with <= saying that it's an invalid AssignmentOperator + my code looks wack I think -

so got stuck whole lot of this:

package test; import javax.swing.*; import java.util.random; import java.util.scanner; public class guessgame { public static void main(string[] args) { scanner keys = new scanner(system.in); system.out.println("hello! play?"); string selection = keys.next(); (choice.equals("y"); choice.equals("yes");) { system.out.println("awesome!"); selection = ""; random bill = new random(); int j; j = bill.nextint(50); system.out.println("guess number i'm thinking "); int number; number = keys.nextint(); (number <= (j + 10); number >= (j - 10);) { system.out.println("warm!"); number = 0; number = keys.nextint(); } (number = (j + 5); number == (j - 10);) { system.out.println("hot!!!"); number = 0; number = keys.nextint(); } } (choice.equals("n"); choice.equals("no");) { system.out.println("okay"); keys.close(); system.exit(0); } } }

on line " (number <= (j + 10); number >= (j - 10);)", i'm getting error on "<=", , i've got no thought how create amends on it. well, i'm not sure if should using statement this. please help me understand mistake, , if there improve alternate for.

thank you!

that because first parameter of for statement used initialization of variable, giving error.

documentation:

for (initialization; termination;increment) { statement(s) }

problem:

for (number <= (j + 10); number >= (j - 10);)

solution:

use if statement if going check both variable

if(number <= (j + 10) && number >= (j - 10))

java eclipse assignment-operator

No comments:

Post a Comment