Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:31:56+00:00 2026-06-06T16:31:56+00:00

I am currently completing my first java course and assignment based on a random

  • 0

I am currently completing my first java course and assignment based on a random number game.
I am having some issues with some if greater and less statements.

I would really appreciate some general comments.

The reason I am looking to input the ‘random’ number is for testing purposes
I also need to incorporate get() and set() methods as the assignment entails object oriented programming so I need to use multiple classes

Any advice would be highly appreciated

The problem I’m having is that the last if statement which checks random number is in range is always getting the output that it is out of range regardless


 package randomnumbergame;

 /*
  * @author Matthew O
  */

import java.util.Scanner;
public class Main {


public static void main(String[] args)
{


int numGuesses = 3;
int rangeMin = 1;
int rangeMax = 10;
int randomNum = 0;

Scanner scan = new Scanner (System.in);


System.out.println("Welcome to the random number game!");
System.out.println("The object of this game is to correctly "
+"guess a number between a set range within a certain ammount of guesses.");
System.out.println("\nThe default range is " + rangeMin + " - " + rangeMax); 
System.out.println("Would you like to change this?");                          
System.out.println("Please enter y for yes or n for no and press enter.");

String range = scan.nextLine();           
char changeRange = range.charAt(0);    
if (! (changeRange == 'Y' || changeRange == 'y'|| changeRange == 'n' || changeRange == 'N'))  
    {
    System.out.println("Error: invalid input entered for the interstate question");   
    System.exit(0);                                                          
    }                                                                           

if (changeRange == 'Y' || changeRange == 'y')       
    {
    System.out.println ("\nPlease enter the new numerical minimum value for the range");      
    int newRangeMin = scan.nextInt();                                              
    rangeMin = newRangeMin;                                  
    System.out.println ("\nPlease enter the new maximum numerical value for the range");       
    int newRangeMax = scan.nextInt();                                               
    rangeMax = newRangeMax;         
    }

{
System.out.println("\nThe default number of guesses is " + numGuesses);         
System.out.println("Would you like to change this?");                           
System.out.println("\nPlease enter y for yes or n for no and press enter.");    

String guesses = scan.next();                                                  
char changeGuesses = guesses.charAt(0);                                         
if (! (changeGuesses == 'Y' || changeGuesses == 'y' || changeGuesses == 'n' || changeGuesses 
== 'N'))                           

    {
System.out.println("Error: invalid input entered for the interstate question");           
System.exit(0);
    }

if (changeGuesses == 'Y' || changeGuesses == 'y')
    {
System.out.println("\nPlease enter the new number of permitted guesses");       
int newGuesses = scan.nextInt();                                               
numGuesses = newGuesses;                                                       
    }

    {
System.out.println ("\n\n\n\n\n\n\n\n\n");                                     
System.out.println("Welcome to the random number game!\n");                     
System.out.println("You have chosen a range of " + rangeMin + " to " + rangeMax);
System.out.println("You have chosen to have " + numGuesses + " Guesses");       
    }
}

{
System.out.println("\nPlease press y to input the random number or n" + 
" to let the number be automatically generated");           
String random = scan.next();                                                    
char changeRandom = random.charAt(0);                                          
if (! (changeRandom == 'Y' || changeRandom == 'y' || changeRandom == 'n' || 
changeRandom == 'N'))                            
    {
    System.out.println("Error: invalid input entered for the interstate question");     
    System.exit(0);
    }

   if (changeRandom == 'Y' || changeRandom == 'y')  
    {
    System.out.println("\nPlease enter the new 'random' number between "
    + rangeMin + " and " + rangeMax);                           
    int inputRandom = scan.nextInt();                                     
    randomNum = inputRandom;                                             
    System.out.println("\nThe 'random' number chosen for the game is " + randomNum);          
    }

if (randomNum < rangeMin);    
    {
    System.out.println("Random number is out of range!");     
    }

    }


 }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:31:58+00:00Added an answer on June 6, 2026 at 4:31 pm

    You have an unnecessary ; at the end of the if statement in question, so even if it is evaluated, the result is nothing.

    if (randomNum < rangeMin); 
                {
                    System.out.println("Random number is out of range!");           
                }
    

    No matter how the if is evaluated, the message will always be printed.

    Change the above to:

     if (randomNum < rangeMin)
                    {
                        System.out.println("Random number is out of range!");           
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I'm building a game with pure UIKit. It's a game where some character
I'm currently completing an assignment that involves using multithreading and multiprocess programming for the
I am currently completing an application that was started by someone else. He is
I'm currently working on an app for the Android OS that displays some data.
I am currently replacing some home baked task functionality with a new implementation using
I'm currently taking a math class in College called Scientific Computing and the professor
I'm currently building a toy assembler in c# (going through The Elements Of Computing
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I am using HTML files for parts of my user interface. I display
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.