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 are some tasks for which you can use the VBA Editor? i need help for my computer class.
Murljashka [212]

Answer:

Visual Basic for Applications runs as an internal programming language in Microsoft Office applications such as Access, Excel, PowerPoint, Publisher, Word, and Visio. VBA allows users to customize beyond what is normally available with MS Office host applications by manipulating graphical-user-interface (GUI) features such as toolbars and menus, dialogue boxes, and forms. You may use VBA to create user-defined functions (UDFs), access Windows application programming interfaces (APIs), and automate specific computer processes and calculations. Macros can automate just about any task—like generating customized charts and reports, and performing word- and data-processing functions. Programmers,like replicating large pieces of code, merging existing program functions, and designing specific languages. VBA can also work in non-Microsoft settings by using a technology called "COM interface," which allows commands to interact across computer boundaries. Many firms have implemented VBA within their own applications, both proprietary and commercial, including AutoCAD, ArcGIS, CATIA, Corel, raw, and SolidWorks.

<em>(Hope this helps/makes sense!)</em>

6 0
3 years ago
What is one advantage of using object-oriented programming?
maxonik [38]
That answer would be B hope it helps
6 0
3 years ago
Read 2 more answers
Which application software would be most suitable for writing a resume?
Gemiola [76]

Answer:

Either word or I would suggest using google docs and word and compare.

Explanation:

You can set up a resume in word.

7 0
2 years ago
Guys for those who are familiar to bubble gum sim...THERE IS A HUGE EVENT AND I DONT WANT TO FAIL AN EVENT...(again) is anyone w
Alborosie
Dude is u still use this app then friend meh on roblox
6 0
2 years ago
A ____ firewall keeps a record of the state of a connection between an internal computer and an external device and then makes d
Yakvenalex [24]

Answer:

Stateful frame filtering

Explanation:

<h2><u>Fill in the blanks</u></h2>

A <u>Stateful frame filtering </u> keeps a record of the state of a connection between an internal computer and an external device and then makes decisions based on the connection as well as the conditions.

8 0
3 years ago
Other questions:
  • The order in which statements are executed during a program run. Answer 1 The first part of a compound statement begins with a k
    12·1 answer
  • Please help?!
    11·2 answers
  • What is called photo and video edition?
    8·1 answer
  • The first computer introduced was the IBM PC. A. True B. False
    11·2 answers
  • You may save more money by using a a0 service, but you will spend more time on creating a contract.
    12·1 answer
  • Test if a number grade is an A (greater than or equal to 90). If so, print "Great!". Sample Run Enter a Number: 98 Sample Output
    7·1 answer
  • All nuclear energy results in the rapid release of energy, such as in atomic bombs. true or false
    8·1 answer
  • An Organization Chart to support the Appliance Warehouse case study The SWOT Analysis diagram you performed and created to suppo
    13·1 answer
  • 9.4 Code Practice: Your task is to determine whether each item in the array above is divisible
    14·1 answer
  • What is missing link describe briefly with an example class 11?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!