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
Which of the following scenarios demonstrates leadership?
bulgar [2K]
I can’t see the scenarios bro
8 0
3 years ago
Read 2 more answers
Is B$4 is an example of a relative cell reference?
yawa3891 [41]
Yes it is because B$4<span> instructs Excel to keep the </span>cell reference<span> B4 (absolute). assumptions </span>
5 0
3 years ago
Some of the items below indicate the steps required to move a slide to a different location in a presentation. Select those step
Ivan

Answer:

Following is the order of steps needed to move a slide to different location:

First: Select the slide

Second: Hold the slide button down

Third: Drag the slide to the desired place.

N/A : Enter the slide position desired.

N/A: Select Move from the Tools menu.

N/A: Switch to the Notes view.

I hope it will help you!

8 0
3 years ago
The use of World Wide Web technology and web design that aims to facilitate creativity, information sharing, and, most notably,
natka813 [3]

Answer:

1. Hosted services

2. Folksonomies

Explanation:

Prior to the invention of Web 2.0, Web 1.0 was in existence. Web 2.0 is a new age technology and system of communication that allows its users to create content on their own and interact more freely with each other.  Before this time, user participation in topics posted online was limited. But today web 2.0 enables such participation with the invention of blogs, and social media sites.  

Creativity is seen in the fact that people are more prone to express themselves through writing, animations, videos, and other forms of communication. Information on new and trending stories are shared through these channels.  Ideas are also exchanged by participants.

4 0
4 years ago
How to determine the critical crack size for a<br> plate
Blababa [14]
Wait what? is that really a question orr
7 0
3 years ago
Other questions:
  • Why have the 'taskmasters' been answering questions so long but they're still only at the ambitious rank?
    14·1 answer
  • What does Pentium means?:/
    7·2 answers
  • Original list:0,0,0,0,0,0,0,0
    10·1 answer
  • Which task should happen during the planning stage of a project? reflect on the project outcomes prevent set-backs determine the
    11·1 answer
  • In the digital age we have less time to absorb and make sense of new information
    12·2 answers
  • true or false then EXPLAIN why. Since many forms of money do not earn interest, people's demand for money is unaffected by chang
    14·2 answers
  • 2×2×2×2×2×2×2×2:-) :-) :-) :-) :-) :-) :-! ​
    11·2 answers
  • Why does the randomNumber function only use whole numbers between 0 and 1 (basically, 0 and 1)?
    13·1 answer
  • 20 points!!!!! Plz answer quickly
    7·1 answer
  • Use the writeln() method of the document object to display the current platform in a tag in the webpage. Hint: The platform prop
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!