I need to solve the the problem in a simple way. kindly tell me how i can print the location of multiple data found in a single line. Suppose there is 100 time value found of 8 then i should print all the locations in a single line.
[img]undefined[/img]
package com.company; import java.util.Arrays; import java.util.List; import java.util.ArrayList; public class Main { public static void main(String[] args) { //Initialize array int [] arr = new int [] {1, 2, 1, 4, 2, 1, 8, 8, 3}; int[] location=new int[10]; System.out.println("Duplicate elements in given array: "); //Searches for duplicate element for(int i = 0; i < arr.length; i++) { for(int j = i + 1; j < arr.length; j++) { if(arr[i] == arr[j]) { System.out.print("value found "+arr[i]+" in multiple positions at location no :"); System.out.print(i +" "+j+" "); System.out.println( ); } } } } }