fix: ReversedString+Palindrom
This commit is contained in:
parent
b79fe73ffb
commit
fb5f689af3
32
reversedString/Palindrom.java
Normal file
32
reversedString/Palindrom.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Palindrom {
|
||||
public static String reversedStr;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String string = sc.nextLine();
|
||||
System.out.println(revString(string));
|
||||
System.out.println(PalindromFlag(string));
|
||||
sc.close();
|
||||
}
|
||||
|
||||
private static String revString(String str) {
|
||||
reversedStr = "";
|
||||
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
char temp = str.charAt(i);
|
||||
reversedStr += temp;
|
||||
}
|
||||
return reversedStr;
|
||||
}
|
||||
|
||||
private static boolean PalindromFlag(String str) {
|
||||
// let's reverse the String first
|
||||
if (str.equals(reversedStr)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user