Write a program to print the repeated values from an Integer Array in an Ascending order
WAP to print the repeated values in an Ascending order From the Integer Array
The below program is to print the repeated values from an Integer array in Ascending order is asked in many interviews,print the repeated values from an integer array in an ascending order please find the below program
package com.st.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.*;
public class SortingTest {
public static void main(String[] args) {
System.out.println("Hello World!");
int a[] = { 2, 2, 2, 1, 4, 4, 3, 3, 3, 1, 9, 9, 1, 5, 7, 8 };
TreeSet<Integer> s = new TreeSet<Integer>();
int c = 0, i = 0, j = 0;
for (i = 0; i < a.length; i++) {
c = 0;
for (j = 0; j < a.length; j++) {
if (a[i] == a[j]) {
c++;
}
}
if (c > 1) {
s.add(a[i]);
}
}
Iterator it = s.iterator();
while (it.hasNext()) {
System.out.print(it.next() + " ");
}
}
}
WAP to print the repeated values in an Ascending order From the Integer Array
The below program is to print the repeated values from an Integer array in Ascending order is asked in many interviews,print the repeated values from an integer array in an ascending order please find the below program
package com.st.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.*;
public class SortingTest {
public static void main(String[] args) {
System.out.println("Hello World!");
int a[] = { 2, 2, 2, 1, 4, 4, 3, 3, 3, 1, 9, 9, 1, 5, 7, 8 };
TreeSet<Integer> s = new TreeSet<Integer>();
int c = 0, i = 0, j = 0;
for (i = 0; i < a.length; i++) {
c = 0;
for (j = 0; j < a.length; j++) {
if (a[i] == a[j]) {
c++;
}
}
if (c > 1) {
s.add(a[i]);
}
}
Iterator it = s.iterator();
while (it.hasNext()) {
System.out.print(it.next() + " ");
}
}
}