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
By using password-stealing software, ________ capture what is typed on a keyboard and easily obtain enough personal information.
wariber [46]

Answer:

B) Keyloggers

Explanation:

Keyloggers are malicious softwares used by hackers to secretly record and capture keystrokes on a person's computer when they are using it. This enables the hackers steal sensitive data like passwords, bank details, address etc. Keyloggers are one of the oldest forms of cyber threats used by cybercriminals to spy on unsuspecting users. Keyloggers can be sent through links to access. computer o directly installed with access to the computer.

5 0
3 years ago
A(n) ___ is an action that causes something to happen.
Luden [163]
Event is an action that causes something to happen
5 0
3 years ago
A computer is performing a binary search on the sorted list of 7 numbers below.
suter [353]

Answer:

The answer is "Option D".

Explanation:

Binary search is also an efficient mechanism for only a sorted item list. It separates the element into one half of the checklist repeatedly, till you have narrowed it down to the only single place.

In this search, the number of comparisons is much more efficient than in the series to use the binary search approach, the items also should be shown, that's why the last choice is correct.

6 0
3 years ago
Read 2 more answers
HELPPP ME PLEASEEE!!
natita [175]
It’s the last one! The key to an effective persuasion is to know what you want and be clear about your response.
4 0
3 years ago
What is the main difference between EDBAC and EDNIAC......​
lawyer [7]

Answer:

EDVAC (Electronic Discrete Variable Automatic Computer) was the successor to ENIAC, was binary based, and used stored programs, and was also designed by Eckert and Mauchly, UNIVAC I (UNIVersal Automatic Computer I) was the first commercial computer. It was designed by the same two men who designed ENIAC and EDVAC.

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • April 107 90 29 31 66 0.344
    8·1 answer
  • Keeping in mind the role the order of precedence plays in equations, what would Excel display as the result of the following equ
    15·1 answer
  • Is a book considered technology?
    8·2 answers
  • The latest form of personal communication that most resembles a public journal is a _____.
    15·2 answers
  • What advantage does a circuit-switched network have over a packet-switched network? What advantages does TDM have over FDM in a
    6·1 answer
  • Why is the cost of a software project not directly related to the cost of development?
    13·1 answer
  • Suppose you are an ad-serving company and you maintain a log of cookie data for ads you serve to the Web pages for a particular
    14·1 answer
  • 5. A Disk defragmenter tool does what to a computer HDD?
    6·1 answer
  • What role does javascript play in a web page
    12·1 answer
  • In large organizations, database design and management is handled by a database _____.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!