Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

random number if else

843785Oct 13 2008 — edited Oct 13 2008
this is the code, why is it saying it expects a ( when it is already present in the string




import java.util.Random; //program uses class Random

import java.util.Scanner;


public class NumberGame
{
public static void main(String[] args)
{
Random randomNumbers = new Random(); //random number genreator
Scanner in = new Scanner(System.in);
int randomValue = randomNumbers.nextInt(101);
int number = generator.nextInt(100) + 1;
int on_off = 1;

while(on_off == 1){
System.out.print("Guess a number between 1 and 100: ");
int guess = in.nextInt();
{
if
(guess < number but within 5)
{
System.out.println("Hot");
}
{
if(guess < number but within 10){
System.out.println("Warm");
}
{
if(guess > number but by no more than 5){
System.out.println("Cool");
}
{
if(guess > number but by no more than 10){
System.out.println("Cold");
}
if(guess == number){
System.out.println("Correct! You win!");
on_off = 0;
}
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2008
Added on Oct 13 2008
1 comment
181 views