-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReverseStrings.java
88 lines (70 loc) · 2.25 KB
/
ReverseStrings.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
87
88
/*
* 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 reversestrings;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author daniel
*/
public class ReverseStrings {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Size of the array, please: ");
int size = input.nextInt();
String[] array = new String[size];
String[] array2 = new String[size];
System.out.println("Enter the values of the array, please: ");
for (int i = 0; i < size; i++) {
array[i] = input.next();
}
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].length();
String maxString = "";
System.out.print("Longest String: ");
for (String str : array) {
if (str.length() > max) {
max = str.length();
maxString = str;
}
}
System.out.println(maxString + "\t Length: " + max);
int min = array[0].length();
String minString = "";
System.out.print("Smallest String: ");
for (String str : array) {
if (str.length() < min) {
min = str.length();
minString = str;
}
}
System.out.println(minString + "\t Length: " + min);
System.out.print("Duplicates: ");
boolean noDuplicates = false;
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
if (!array[i].equals(array[j])) {
noDuplicates = true;
} else {
System.out.print(array[i] + " ");
}
}
}
if (noDuplicates) {
System.out.println("none");
}
System.out.println();
}
}