-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReverseIntegers.java
86 lines (66 loc) · 2.05 KB
/
ReverseIntegers.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package reverseintegers;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author daniel
*/
/*
* java program to reverse an array
* and the user should determine the number of values in the array
* program to determine minimum and max values of the array
* and it determines duplicate values in the array
*/
public class ReverseIntegers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Size of the array, please: ");
int size = input.nextInt();
int[] array = new int[size];
int[] array2 = new int[size];
System.out.println("Enter the values of the array, please: ");
for (int i = 0; i < size; i++) {
array[i] = input.nextInt();
}
System.out.println(Arrays.toString(array));
System.out.println("Reverse:");
for (int i = size - 1, j = 0; i >= 0; i--, j++) {
array2[j] = array[i];
}
for (int i = 0; i < size; i++) {
array[i] = array2[i];
System.out.print(array[i] + " ");
}
System.out.println();
int max = array[0];
System.out.print("Max: ");
for (int i = 1; i < size; i++) {
if (array[i] > max) {
max = array[i];
}
}
System.out.println(max);
int min = array[0];
System.out.print("Min: ");
for (int i = 1; i < size; i++) {
if (array[i] < min) {
min = array[i];
}
}
System.out.println(min);
System.out.print("Duplicates: ");
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
if (array[i] == array[j]) {
System.out.print(array[i] + " ");
}
}
}
System.out.println();
}
}