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
PLS HURRY!!<br> Look at the image below!
Lady_Fox [76]

Answer:

Line 2: for numF in [3, 5]

Line 1: for numE in [2, 6]

Line 3: print(numE, numF)

Explanation:

From the outputs, the first number of the first output is 2. This means that <em>numE in [</em><em>2</em><em>, 6]</em> would be on the first line.

The second number of the first output is 3, concluding that <em>numF in [</em><em>3</em><em>, 5]</em> is within a nested loop, meaning it would be on the second line.

This leaves <em>print(numE, numF)</em> on line 3.

We can go through the lines step by step to check if we have placed them in the correct order:

Code

for numE in [2, 6]:

 for numF in [3, 5]:

   print(numE, numF)

During the first iteration, numE = 2 and numF = 3.

Output: 2, 3

Since [3, 5] is in a nested loop, we need to finish iterating all of its numbers before numE moves to the next number, so:

numF moves to 5, numE stays at 2.

Output: 2, 5

Since we have finished iterating through [3, 5], numE moves to 6 and numF starts back at 3:

Output: 6, 3

numE still stays at 6 and numF iterates to 5 since [3, 5] is in a nested loop:

Output: 6, 5

The outputs match the outputs on the sheet, meaning we have correctly placed the code in order.

Hope this helps :)

5 0
3 years ago
Employee names are stored using a maximum of 50 characters. This information is an example of which of the following?
enyata [817]

Answer: Data model

Explanation: Data model is the arrangement of the information in the form of table structure to maintain it in the form of database.They help in the keeping the entities in the sequence and can be tracked when required.Example- vendors records,customer record etc.

Other options are incorrect because the data retrieval is the regaining of the data from database, record instance is the parts of the database records  and meta data give knowledge about other data.

8 0
4 years ago
Where do we manage POS? ​
valkas [14]

Explanation:

<em>The</em><em> </em><em>POS</em><em> </em><em>serves</em><em> </em><em>as</em><em> </em><em>the</em><em> </em><em>central</em><em> </em><em>component</em><em> </em><em>for</em><em> </em><em>your</em><em> </em><em>business</em><em>;</em><em> </em><em>it's</em><em> </em><em>the</em><em> </em><em>hub</em><em> </em><em>where</em><em> </em><em>everything</em><em> </em><em>like</em><em> </em><em>sales</em><em>,</em><em> </em><em>inventory</em><em> </em><em>management</em><em> </em><em>,</em><em> </em><em>payment</em><em> </em><em>processing</em><em>,</em><em> </em><em>and</em><em> </em><em>customer</em><em> </em><em>management</em><em> </em><em>merges</em><em>.</em><em> </em>

3 0
3 years ago
You can use a(n) ____ to visually separate related controls from other controls on the form.
maksim [4K]

Answer:

The correct answer to the following question will be Group Box.

Explanation:

Group Box:

  • A type container that contains many types of controls that are usually related to each other in the form.
  • It usually provides the identified grouping for other controls.
  • used for the subdivision of the forms.
  • Separation of the controls can be done with the help of grouping by group box.

5 0
3 years ago
. What year did the USA host World Cup? Right answer 1994
Ksivusya [100]

Answer:

USA host World Cup in 1994 1994 FIFA World Cup

Explanation:

USA host World Cup in 1994 FIFA World Cup

it was the 15th edition of FIFA World Cup

and Brazil was won the tournament

Brazil beat Italy by 3–2 in  penalty shoot-out

it was play between 17 June to 17 July and 24 team play this World Cup

and there matches played = 52

and 9 cities host this game

United States of America was chosen as the host by FIFA on the 4 July, 1988

5 0
3 years ago
Other questions:
  • The best-known communications protocol is probably smtp, which regulates internet data transport. _________________________
    6·1 answer
  • 1) Prompt the user to enter two words and a number, storing each into separate variables. Then, output those three values on a s
    11·1 answer
  • Does this look anywhere close to the APA Format?
    6·1 answer
  • Flowcharts allow you to more easily clarify among multiple potential solutions to a problem to see which solution is best.
    5·1 answer
  • Find different between manocots and dicots clarify with example​
    14·1 answer
  • A carver begins work on the following block of granite that weighs 2700 g. What is the density of the granite?
    13·1 answer
  • You wrote a program to allow to guess a number chosen randomly.
    10·2 answers
  • Helpppppp meeeeeeeeeeeeeeeeee
    12·1 answer
  • 6. A genre of video game in which a player chooses a character and builds, upskills and modifies that character is referred to a
    12·2 answers
  • Please help me i’ll give you brainlist
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!