-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeatCount.java
More file actions
35 lines (30 loc) · 939 Bytes
/
Copy pathrepeatCount.java
File metadata and controls
35 lines (30 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class repeatCount
{
static void printRepeat(final int arr[], final int size) {
final int count[] = new int[size];
int i;
System.out.print("The repeating digits are: ");
for (i = 0; i < size; i++) {
if (count[arr[i]] == 1)
System.out.print(arr[i] + " ");
else
count[arr[i]]++;
}
}
static void countSign(int arr[], int len) {
int i;
System.out.println("The repating digits by using signs are ");
for (i = 0; i < len; i++) {
if (arr[Math.abs(arr[i])] > 0)
arr[Math.abs(arr[i])] = -arr[Math.abs(arr[i])];
else
System.out.println(Math.abs(arr[i]));
}
}
public static void main( String[] args) {
int arr[] = { 1, 2, 3, 4, 3, 2, 1 };
int len = arr.length;
// printRepeat(arr,7);
countSign(arr, len);
}
}