Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Java

Write code statements to create an array based on user values and determine if that array contains at least one unique value.

Code Specifications

All of your code can go in the main method.

  1. Ask the user how many numbers they want to enter.
  2. Create an int[] using this size.
  3. Use a loop to read in the user's values and store them in the array.
  4. Determine if there is at least one unique value in the array.
    • Hint: use a nested loop!
  5. Output the result to the user.

What I have so far:

import java.util.Scanner;

public class UniqueNumbers {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("How many numbers do you want to enter?");
        int numbers = Integer.parseInt(scan.nextLine());
        
        int[]values = new int[numbers];
        for(int i = 0; i<values.length; i++) {
            System.out.println("Enter a number:");
            values[i] = Integer.parseInt(scan.nextLine());
        }
        

    }

}

The picture is a table of test cases. I just need you to add the code that determines if there is a unique value

Number
of
Numbers
5
5
4
6
3
4
4
5
Values in
the Array
{1, 2, 3, 4,
5}
{1, 2, 2, 1,
3}
(3, 5, 1, 1)
{6, 8, 2, 8,
6,5}
{4, 4, 4]
{7,7,7,7}
{1, 2, 1, 2}
{4, 4, 3, 4,
3}
Contains a
Unique
Number?
yes
yes
yes
yes
no
no
no
no
expand button
Transcribed Image Text:Number of Numbers 5 5 4 6 3 4 4 5 Values in the Array {1, 2, 3, 4, 5} {1, 2, 2, 1, 3} (3, 5, 1, 1) {6, 8, 2, 8, 6,5} {4, 4, 4] {7,7,7,7} {1, 2, 1, 2} {4, 4, 3, 4, 3} Contains a Unique Number? yes yes yes yes no no no no
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY