-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP8_String.java
More file actions
74 lines (52 loc) · 1.45 KB
/
Copy pathP8_String.java
File metadata and controls
74 lines (52 loc) · 1.45 KB
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
package unit_01;
/* Problem Statement:
P8_String:
(Create separate logic in separate function)
F1 - Check the entered string is palindrome or not?
String s = "75457"
Output: Yes it is a palindrome or No it is not a palindrome.
F2 - Make a reverse of a string using?
F3 - String Compare: Check if the strings are equal or not?
* */
public class P8_String {
public static void main(String[] args) {
QuestionsOnString obj = new QuestionsOnString();
String s1 = new String("75457");
String s2 = new String("7545a");
obj.palindromeOrNot(s1);
obj.reverseOfAString(s1);
obj.stringEqualOrNot(s1, s2);
}
}
class QuestionsOnString {
void palindromeOrNot(String s)
{
String s1=new String("75457");
String reverseStr = "";
int strLength = s1.length();
for (int i = (strLength - 1); i >=0; --i) {
reverseStr = reverseStr + s1.charAt(i);
}
if (s1.toLowerCase().equals(reverseStr.toLowerCase())) {
System.out.println(s1 + " is a Palindrome String.");
}
else {
System.out.println(s1 + " is not a Palindrome String.");
}
}
void reverseOfAString(String s)
{
String s1=new String();
for(int i = s.length()-1; i >= 0; i--){
s1 = s1 + s.charAt(i);
}
System.out.println("Reverse string: " + s1);
}
void stringEqualOrNot(String s1,String s2)
{
if(s1.equals(s2))
System.out.println(" Strings(s1 and s2) are Equal");
else
System.out.println(" Strings(s1 and s2) are Not Equal");
}
}