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

  • Home
  • SEARCH
  • 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 811647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:04:41+00:00 2026-05-15T01:04:41+00:00

I am a newbie Computer Science high school student and I have trouble with

  • 0

I am a newbie Computer Science high school student and I have trouble with a small snippet of code. Basically, my code should perform a basic CLI search in an array of integers. However, what happens is I get what appears to be an infinite loop (BlueJ, the compiler I’m using, gets stuck and I have to reset the machine). I have set break points but I still don’t quite get the problem…(I don’t even understand most of the things that it tells me)

Here’s the offending code (assume that “ArrayUtil” works, because it does):

import java.util.Scanner;
public class intSearch
{
   public static void main(String[] args)
   {
       search();
   }

   public static void search()
   {
       int[] randomArray = ArrayUtil.randomIntArray(20, 100);
       Scanner searchInput = new Scanner(System.in);
       int searchInt = searchInput.nextInt();
       if (findNumber(randomArray, searchInt) == -1)
       {
           System.out.println("Error");
       }else System.out.println("Searched Number: " + findNumber(randomArray, searchInt));
   }

   private static int findNumber(int[] searchedArray, int searchTerm)
   {
      for (int i = 0; searchedArray[i] == searchTerm && i < searchedArray.length; i++)
      {
          return i;
      }
      return -1;
   }
}

This has been bugging me for some time now…please help me identify the problem!

  • 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-05-15T01:04:41+00:00Added an answer on May 15, 2026 at 1:04 am

    I don’t know what is the class ArrayUtil (I can not import is using my Netbeans). When I try to change that line with the line int[] randomArray = {1 , 2, 3, 5, 7, 10, 1 , 5}; It works perfectly.

    And you should change the loop condition. I will not tell you why but try with my array and you will see the bug soon. After you see it, you can fix it:)

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

Sidebar

Related Questions

I'm a newbie to programming. I had 1 semester of computer science (we used
I am an absolute newbie without even a computer science background. I am just
newbie here, so thanks in advance for help! I have a Wordpress site with
Newbie question... The objective: I intend to have an HTML text input field as
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I am a python django newbie, and was going through some open source code,
I'm a complete newbie in the computer vision world and recently I implemented some
Newbie here, I have a struct for a word, which contains a char array
I am a newbie and I have installed Win server 2003, SP 2007 and
I am newbie in cryptography and pycrypto. I have modulus n and private exponent

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.