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]
3 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]3 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
When I click on someone who asked a question and i want to see there answer it is always blurred and when I asked a question I c
yuradex [85]

Answer:

If your on pc like me use ad blocker I do that but otherwise watch the add press ok after if it dosemt work tell me I’ll try and find you it and for ad blocker you also can have a jailbreak divice and to get and blocker go to chrome extension website search up pop up ad blocker

Explanation:

7 0
3 years ago
Why team goals should be broken into shon-term, medium-term, and long-term goals
lora16 [44]

Answer:

Explanation: Goals should be broken down according to time because it allows the team to decide what their overall purpose is, and to define the actions that will allow them to achieve their overall purpose.

7 0
3 years ago
Read 2 more answers
Expressions coded in the HAVING clause
HACTEHA [7]

Answer:

A

Explanation:

Expressions coded in the HAVING clause can use either aggregate search conditions or non-aggregate search conditions.

Cheers

7 0
3 years ago
Make a list of any four computer that were used in the history of computer.​
blondinia [14]

Answer:

ENIAC, UNIVAC, EDVAC and IMB 1401 are the list of computers used in history of computer

Explanation:

hope it helps

plz make it brainliest ans

7 0
3 years ago
What is a router?
DIA [1.3K]

Answer:

A) a device that sends data to the receiving device

Explanation:

3 0
3 years ago
Other questions:
  • How can you create the first row of the table as the header of the table?
    14·2 answers
  • . Business-to-business integration (B2Bi) is vital for efficient and accurate flow of data across internal ISs and external busi
    11·1 answer
  • Where is the typical location of a touchpad inside of a laptop?
    13·1 answer
  • Data flow is not a major consideration when building an analytics model. T/F
    13·1 answer
  • Why would Network Systems employees be employed by the government?
    12·2 answers
  • Many contemporary languages allow two kinds of comments: one in which delimiters are used on both ends (multiple-line comments),
    7·1 answer
  • Prove that the dual of the exclusive-OR gate is also itscomplement
    10·1 answer
  • Edhesive 2.3 code practice question 1​
    11·1 answer
  • A sensitive manufacturing facility has recently noticed an abnormal number of assembly-line robot failures. Upon intensive inves
    10·1 answer
  • Fill in the blank: Every database has its own formatting, which can cause the data to seem inconsistent. Data analysts use the _
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!