Code to Check Whether the entered String is Dupledrome or Not.
Dupledrome means that every element present in the String should be present twice i.e., "rattar" is a dupledrome string whereas "rasrat" is not a Dupledrome String.import java.util.Scanner; //Scanner Class
public class DupledromeChecking {
static boolean isDupledrome(String ap)
{
int N = ap.length();
char[] ar = new char[N]; //Char Array
ar = ap.toCharArray();
int i,k=0,q=0,r=0,j;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(ar[i]==ar[j]) //When Values are Equal
{
r++; //Increment The Count
}
}
}
/*If The Counted Value is Equal to Twice the Lenght
then it is Said that every element present
exactly twice */
if(r==(N*2))
{
return true;
}
else
{
return false;
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in); //Scanner Object
System.out.println("Program to Check Whether the Entered String is Dupledrome or Not");
System.out.print("Enter the String:- \t");
String s1 = sc.next();
boolean result = isDupledrome(s1); //Calling Function
System.out.println("Dupledrome String:- \t"+result);
}
}
No comments:
Post a Comment