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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:20:01+00:00 2026-05-25T13:20:01+00:00

I am writing a simple program where the user enters a name and an

  • 0

I am writing a simple program where the user enters a name and an integer. If the integer was not already used, the name goes into an array. My problem is that I can’t seem to figure out how to check the integer when it is entered to see if it was already used (duplicated). I tried putting the integers into an array, but could not get it to work. Please keep in mind that I am a complete novice. So in the code below, after the user enters a name, he/she enters a time (integer) and if the time was not already used, it is valid; if it was used, I’ll need to throw an exception. So far, all I have is the code working for the name (adding it to the array).

public void enterName()
{

    Scanner keyboard = new Scanner(System.in);

    for(i = 0; i < arrayNames.length; i++)
    {           
        System.out.println("Please enter your name.");
        names = keyboard.nextLine();

            arrayNames[i] = names;              
            System.out.println("name is in");           
    }
    System.out.println("array is full");


}
  • 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-25T13:20:01+00:00Added an answer on May 25, 2026 at 1:20 pm

    If you absolutely must use an array, here’s how to check for duplicate entries:

    public boolean contains(int[] numbers, int searchedNumber) {
        for (int number : numbers) {
            if (number == searchedNumber) {
                return true;
            }
        }
    
        return false;
    }    
    

    EDIT

    The expression for (int number : numbers) basically means for each int of the int array do. Internally, an Iterator is created, which is then used to iterate over the elements of the array (or collection).

    But for the moment, you can think of it being (semantically) the same as:

    for (int i = 0; i < numbers.length; i++) {
        if (numbers[i] == searchedNumber) {
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple program that is used to synchronize files to an FTP.
I'm writing a program that calculates input a user gives, simple numbers. 2, 4,
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
I am writing a java program in eclipse(galileo version). The program reads simple user
I am writing a simple program to insert rows into a table.But when i
I'm writing a tiny program that takes user input using Getops, and based on
I'm just a beginner in C++. I'm writing small and simple program that prints
I am learning C and writing a simple program that will take 2 string
I'm writing a very simple program where I want to get user input from
I'm writing simple program to communicate between smart devices and I receive 11001 when

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.