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
butalik [34]
3 years ago
8

Find a duplicate (10 points). Write a program FindDuplicate.java that reads n integer arguments from the command line into an in

teger 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
2 answers:
mestny [16]3 years ago
7 0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 int n;

 Scanner input = new Scanner(System.in);

 System.out.print("Enter the array size: ");

 n = input.nextInt();

 

 int[] numberArray = new int[n];

 

 System.out.print("Enter the numbers between 1 and " + n + ":");

 

 for(int i=0; i<n; i++){

     numberArray[i] = input.nextInt();

 }

 

 System.out.println(findDublicate(numberArray, n));

}

public static boolean findDublicate(int[] numberArray, int n){

    boolean flag = false;

    for (int i = 0; i < n; i++) {

        for (int j = i + 1 ; j < n; j++) {

            if (numberArray[i] == numberArray[j]){

                 flag = true;

                 break;

            }

        }

    }

    return flag;

}

}

Explanation:

<u>Inside the function:</u>

- Check if there are duplicates by comparing each number in the array using nested for loop

<u>Inside the main:</u>

- Ask the user for array size and the numbers

- Put them into the array called <em>numberArray</em>

- Call the function and print the result

Galina-37 [17]3 years ago
3 0

Answer:

import java.util.Arrays;

import java.util.Random;

public class FindDuplicate {

   public static void main(String[] args) {

       // Declare an array of size n

       // assume n=10

       int n=10;

       boolean duplicate =true;

       int [] intArray = new int[n];

       Random rand = new Random();

       //Reading n values into the array using a for loop

       for(int i=1; i<n; i++){

           intArray[i]= rand.nextInt(11);

       }

       System.out.println(Arrays.toString(intArray));

       for(int i = 0; i < n; i++) {

           for(int j = i + 1; j < n; j++) {

               if(intArray[i] == intArray[j]) {

                   duplicate = true;

break;

           }

     }

  }

       if(duplicate){

           System.out.println("True");

       }

       else{

           System.out.println("False");

       }

   }

}

Explanation:

Using Java programming language

An Array is declared of size n =10

Using the Random class random integers from 1-10 inclusive are generated and loaded into the array (using a for loop)

 To find duplicate elements, two for loops are used. The first loop (outer) iterates through the array and selects an element, The inner loop is used for comparison of the selected element with other elements in the array.

If there is a match, the boolean variable duplicate will be set to true

And True is printed to the screen, else False is printed

You might be interested in
Find every number from 1 to n (inclusive) that is a palindrome which starts with the digit 3. Do not user a helper function.
Mkey [24]

Answer: Following code is in python

n=input()

num='1'

while int(num)<=int(n):    //loop from 1 to n

   flag=1   //if an unequal element will be found it will be 0

   l=len(num)

   if num[0]=='3':

       j=0

       k=l-1

       while j<k:    //loop till middle of number

           if num[j]==num[k]:

               j+=1     //from beginning

               k-=1    //from end

           else:

               flag=0

               break

       if flag==1:

           print(int(num))

   num=str(int(num)+1)    //number will be incremented as integer

INPUT :

1000

OUTPUT :

3

33

303

313

323

333

343

353

363

373

383

393

Explanation:

In the above code, a loop is executed till num is equal to n which is entered by the user. num is treated as a string so that to ease the process of checking first character is 3 or not. If it is 3 then another loop executes which checks if an element from starting is equal to the corresponding element from the end. If an element is not equal then the flag is changed and then we break out of the loop and prints the number if the flag isn't changed.

7 0
4 years ago
What is a written or electronic document that outlines etiquette policies for using networks and network resources?
daser333 [38]

Acceptable Use Policy is a written or electronic document that outlines etiquette policies for using networks and network resources.

Therefore, the answer is Acceptable Use Policy.

3 0
3 years ago
Of the key reasons for creating organizational units which of the following is not one of them?
victus00 [196]
There are no answrt choices it would be very helpful if you added them, then I could help you.
5 0
3 years ago
A network administrator is configuring an ACL with the command access-list 10 permit 172.16.32.0 0.0.15.255. Which IPv4 address
lord [1]

Answer:

For this wild card mask 0.0.15.255 the ACE IP address will be 172.16.47.254

Explanation:

ACL is the access control list that is used to enlist the ip addresses that allowed or restricted to access the network. ACE is an IP address from the list ACL that has all rules and regulations related to access of network. The ACE could be in the range of IP address in ACL. ACL can be calculated with the help of initial IP address adding with wild card mask.

So

Initial IP address is = 172.16.32.0

Wild card mask =0.0.15.255

by adding above values we can find the last IP address of ACL.

after addition

Final IP address is = 172.16.47.255

The options that are available with question, Only option between the range is  172.16.47.254. So we can say that This is the only ACE IP address in options.

7 0
3 years ago
When working in Photoshop with the move tool, you can select multiple layers and use this option to arrange them into a straight
wel

Answer:

Distribute -  will put all of the layers in a straight line across the image

6 0
4 years ago
Read 2 more answers
Other questions:
  • What do i study to become a network engineer?
    11·1 answer
  • If you want to copy text formatting from one area of your document to another area, _____.
    5·2 answers
  • Help with this chart please
    9·1 answer
  • The network architecture component that is a special LAN with a group of servers that enables electronic data exchange of betwee
    8·1 answer
  • Explain the use of keyboard shortcuts and key combinations. You are at the tenth page of a 20-page document. You need to make ch
    14·1 answer
  • 2. Given the following list, write a snippet of code that would print the individual elements of the list using the indexes of t
    13·1 answer
  • List the gcc command-line options for each of the following: Generate a .o file rather than an executable. Generate a .s (assemb
    6·1 answer
  • In a Microsoft Office application, what is the area at the bottom of the application screen that contains information about the
    13·1 answer
  • Give four advantages for ssd compared to hdd
    15·2 answers
  • Why do you think Jacinda believed what people told her about her own beauty? Even if you understand that what you see on social
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!