Question

Write a Java program to find the duplicate values of an array of integer values. import...

Write a Java program to find the duplicate values of an array of integer values.

import java.util.Arrays;
public class ex7DuplicateValue {
  public static void main(String[] args)
    {
int[] my_array = {1, 2, 3, 3, 4, 5, 6, 2};

} }

//Duplicate Element : 2
//Duplicate Element : 3
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

import java.util.Arrays;
public class ex7DuplicateValue {
public static void main(String[] args)
{
int[] my_array = {1, 2, 3, 3, 4, 5, 6, 2};

for (int i = 0; i < my_array.length-1; i++)
{
for (int j = i+1; j < my_array.length; j++)
{
if ((my_array[i] == my_array[j]) && (i != j))
{
System.out.println("Duplicate Element : "+my_array[j]);
}
}
}
}

}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a Java program to find the duplicate values of an array of integer values. import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • Write a java program that declares 10 element array (of type integers), creates and initializes the...

    Write a java program that declares 10 element array (of type integers), creates and initializes the array, and perform the sum of elements of the array using for loop.   public class SumArray { public static void main (String[], args) { } // end of main } // end of SumArray class

  • Write a program that uses the selection sort algorithm to sort an array of coins by...

    Write a program that uses the selection sort algorithm to sort an array of coins by their value. Name your class SelectionSorter.java and include the method public static void sort(Coin[] a). The following classes are already included: Main.java and Coin.java and do not need to be downloaded and zipped into submission. Console [15, 5, 1, 100, 25, 50] [1, 5, 15, 25, 50, 100] Input Files Coin.java //package Sorting1; /** A coin. */ public class Coin { private int value;...

  • (JAVA) Given an array of unique positive integers, write a function findSums that takes the array...

    (JAVA) Given an array of unique positive integers, write a function findSums that takes the array input and: 1. Creates a hashtable called “hashT” and inserts all the elements of the input array in the hashtable. 2. Finds pairs of elements in the hashtable whose sum is another element (sum) in the hashtable and print the pairs in the console. 3. Returns another hashtable names “sums” of those sum elements. For example: Input: [1,5,4,6,7,9] Output: [6,5,7,9] Explanation: 6 = 1...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • Write a program that stores a phrase as an array of words, and then prints it...

    Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{    public static void main(String[] args) {    String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...

  • Question 2: Execute the following program. import java.util.Arrays; public class ArrayManipulations { public static void main(String[]...

    Question 2: Execute the following program. import java.util.Arrays; public class ArrayManipulations { public static void main(String[] args) { // sort doubleArray into ascending order char [] A = {'g', ', 'y', 'a', 'e','d' }; Arrays.sort( A); for (char value: A) System.out.printf("%2C", value); System.out.printf("\n"); char [] A Copy = new char[ 3 ]; System.arraycopy( A, 2, A Copy, 0, A Copy.length); for(char value: A Copy) System.out.printf("%2C", value); System.out.printf("\n"); int location = Arrays.binary Search(A Copy, 'y'); if(location >=0) System.out.printf("y Found at element...

  • write a program to handle an exception that is generated when a program attempts to write...

    write a program to handle an exception that is generated when a program attempts to write beyond the end of an array in a lower scope such that that the exception is handled at a higher scope. java please write simple code so I can understand. use the code below public class Main { public static void main(String [] args) { int [] values = {1,2,3,4}; try { int theSum= calculate_sum(values); } catch (expection arrayindexoutofBoundsexpection) { //System.out.println(“tired to access array...

  • Please update this java code so 1. A scanner can be used to import the files....

    Please update this java code so 1. A scanner can be used to import the files. Then compute and test with a randomly generated array instead of a file. Compute all possible distinctive pair of values from an an array. [A,B,C, A] A,B A,C B,C - i.e. (A,B)==(B,A) (A, A) is not valid hint: sort the array first Example: input [1, 2, 3, 2, 3, 4, 3] result 4 (with distinct pairs) and 8 (with symmetric pairs import java.util.Arrays; import...

  • Ch. 09: Exclusive find in Array (Arrays, conditional, counter) Write a method that will receive an...

    Ch. 09: Exclusive find in Array (Arrays, conditional, counter) Write a method that will receive an array of integers and an integer value as a parameter. The integer value received as the second parameter will be searched within the Array received as the other parameter. The method will return true if the value appears only once in the Array. Use the "documentation shown in the program as a guide". As an example, if the array received was the sequence of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT