-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaMethods.java
43 lines (27 loc) · 1019 Bytes
/
JavaMethods.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
package javaPack;
public class JavaMethods {
/*** 1. This method is used to reverse a string. ***/
public static String reverse(String input) {
String reversed = "";
/***Check if the input value is not null. If null, then do not accept.***/
if(input.isEmpty() || input.equals(null)) {
System.out.println("The input string is empty/null.");
}
/*** Check if the input String consist of more than one characters. Else, returns the same chararter as output ***/
if(input.length() <= 1) {
input = reversed;
}
/*** Reversing the String. ***/
if(input.length() > 1) {
String [] arrInput = input.split("\\s+"); // Splitting the input from spaces using regex.
for(String ipElement: arrInput) {
reversed = ipElement + " " + reversed;
}
}
return reversed.trim();
}
/*** Invoking the constructor using the super() keyword. ***/
JavaMethods() {
System.out.println("This is super class");
}
}