There are various methods:
One of them is:
public class LivingBeing {
public static void main(String[] args) {
String str = "LEVEL";
boolean flag_1 = false;
for(int i = 0; i<str.length(); i++){
if(str.charAt(i) == str.charAt(str.length()-i-1)){
flag_1 = true;
}
else {
flag_1 = false;
}
}
if (flag_1 == true){
System.out.println("Anagram");
}
}
}
One of them is:
public class LivingBeing {
public static void main(String[] args) {
String str = "LEVEL";
boolean flag_1 = false;
for(int i = 0; i<str.length(); i++){
if(str.charAt(i) == str.charAt(str.length()-i-1)){
flag_1 = true;
}
else {
flag_1 = false;
}
}
if (flag_1 == true){
System.out.println("Anagram");
}
}
}
No comments:
Post a Comment