possible palindrome or not

Write a java program to check that string is possible to make palindrome or not.........


import java.util.Scanner;
public class PossiblePalindrome {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter a String : ");
String str=sc.nextLine();
char[] arr=str.toCharArray();
int[] index=indexNumber(arr);
boolean res=possPalin(index);
if(res) {
System.out.println("yes it is possible to make palindrome");
}
else {
System.out.println("no it is not possible to make palindrome ");
}
}
static int[] indexNumber(char[] arr) {
int index[]=new int[26];
for(int i=0;i<arr.length;i++) {
char ch=arr[i];
if(ch>64 && ch<91) {
index[ch-65]++;
}
else if(ch>=97 && ch<=122) {
index[ch-97]++;
}
}
return index;
}
static boolean possPalin(int arr[]) {
int count=0;
for(int i=0;i<arr.length;i++) {
int num=arr[i];
if(num%2!=0) {
count++;
}
if(count>=2) {
return false;
}
}
return true;
}

}

Comments

Popular posts from this blog

program to calculate product of each column in matrix