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 8706973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:45:00+00:00 2026-06-13T03:45:00+00:00

I am making a binary search tree (BST) and a randomized BST. All of

  • 0

I am making a binary search tree (BST) and a randomized BST. All of my methods for both of these work and I’m stuck on what I feel is more simple. The code that is failing is pretty simple. As an aside, I’m using standard redirection to read the values, so I input a lot of values at once, not one at a time.

while ( console.hasNextInt() ) {
   key = console.nextInt();
   System.out.println(key);
   head.remove( key );
}

Where console is the name of my scanner, and key is a global variable used to read in the keys for the trees. Debugging shows that it goes through the loop correctly until after the final integer is read. After that it appears to reenter the while loop even though there are no more integers to read. I’m obviously making a mistake somewhere but it’s not obvious to me and I’ve spent a couple of hours trying to reword this to no avail. Any help would be greatly appreciated.

EDIT – An example of what I am inputting is:

820426496
648711744
834882112
261937632
475255968
311993216
834882112

It reads in every number until 834882112 and then enters back into the while loop and I don’t know why.

As far as the code, this is exactly the code that is messing up. Everything else is just setting up the scanner, etc.

  • 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-13T03:45:01+00:00Added an answer on June 13, 2026 at 3:45 am

    As I said in my comment, hasNextInt() returns true if the next token in the stream is an int, and false if it is not an int. Once the loop has read the last int, hasNextInt() simply waits for the next token to be entered to decide if it’s a valid integer or not. If you want to stop the loop, you need to enter something which is not an integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Binary Search Tree that I'm making and I implemented the Insert
I am developing a binary search tree in java. But i am facing certain
I'm making a simple vim function that counts to n in binary (each number
Given a binary search tree, in which any two nodes are swapped. So we
This question is related to a Binary Search tree. Here is the definition of
I'm trying to eliminate any memory leaks in in my Binary Search tree that
I'm making a tree that has several different node types: a binary node, a
Making a simple application, so when the user logs out of Windows, it of
Motivation: I want to use bsearch (binary search) to quickly search through a sorted
for data retrieval i need to use binary keyword for case sensitive search in

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.