1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nataliya [291]
2 years ago
11

Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where

each value is between is 1 and n, and displays true if there are any duplicate values, false otherwise.
Computers and Technology
1 answer:
kozerog [31]2 years ago
7 0

Answer:

  1. public class FindDuplicate{
  2.    public static void main(String[] args) {
  3.        Scanner input = new Scanner(System.in);
  4.        int n = 5;
  5.        int arr[] = new int[n];
  6.        for(int i=0; i < arr.length; i++){
  7.            int inputNum = input.nextInt();
  8.            if(inputNum >=1 && inputNum <=n) {
  9.                arr[i] = inputNum;
  10.            }
  11.        }
  12.        for(int j =0; j < arr.length; j++){
  13.            for(int k = 0; k < arr.length; k++){
  14.                if(j == k){
  15.                    continue;
  16.                }else{
  17.                    if(arr[j] == arr[k]){
  18.                        System.out.println("True");
  19.                        return;
  20.                    }
  21.                }
  22.            }
  23.        }
  24.        System.out.println("False");
  25.    }
  26. }

Explanation:

Firstly, create a Scanner object to get user input (Line 4).

Next, create an array with n-size (Line 7) and then create a for-loop to get user repeatedly enter an integer and assign the input value to the array (Line 9 - 14).

Next, create a double layer for-loop to check the each element in the array against the other elements to see if there is any duplication detected and display "True" (Line 21 - 22). If duplication is found the program will display True and terminate the whole program using return (Line 23). The condition set in Line 18 is to ensure the comparison is not between the same element.

If all the elements in the array are unique the if block (Line 21 - 23) won't run and it will proceed to Line 28 to display message "False".

You might be interested in
What does a cascading style sheet resolve a conflict over rules for an element?
Margaret [11]
I Think The answer is d I hope it helps
4 0
3 years ago
How do multi-cellular organisms develop?
FromTheMoon [43]
Letter B. is the answer
<span>B.  Cell differentiation - start from a single cell and as the cells divide they become specialized</span>

HOPE THIS HELPS















4 0
3 years ago
Enzymes_____________.
lord [1]

Answer:

b. speed up chemical reactions.

Explanation:

brainly plz

4 0
2 years ago
How to download ram<br> my computer is very slow and I need more ram
AURORKA [14]

Answer:

It is not possible to download RAM onto your computer.

Explanation:

RAM (Random-Access Memory) are physical objects installed onto your computer in the form of some sort of chip. Please do not attempt to download RAM from the internet, you may end up with malicious software on your computer. The only way to get more RAM is by installing more onto your computer or by looking at guides that can explain how to free up some RAM that may already be in use by an application.

8 0
3 years ago
Read 2 more answers
Right now I have an i5 2400 and a PYN XLR8 gaming GTX 1650 Super, my CPU is too weak for 1080p gaming, what CPU should I get tha
Dmitry_Shevchenko [17]

Answer:

if its a number you need 5600GHz but im not to sure

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • A security administrator is required to submit a new csr to a ca. what is the first step?
    11·1 answer
  • Home communication involves controlling systems such as heating, cooling, and security.
    11·1 answer
  • Jerry is making an address book using a digital database. He has a list of his immediate family and friends but wants to add a f
    9·2 answers
  • The commands available here change depending on the activity taking place in the presentation window's main work area.
    15·2 answers
  • What will be displayed after the following code is executed? def pass_it(x, y): z = x*y result = get_result(z) return(result) de
    13·1 answer
  • What does snap do need the answer now
    10·2 answers
  • You are given 6 training examples for a binary classification problem as follows:
    12·1 answer
  • Pls tell me the answer pls i need the answer
    6·2 answers
  • The command to get out of the loop.<br>a.<br>i exit<br>ii. break<br>iii. comment<br>iv. for​
    12·1 answer
  • Page No
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!