Question: Lab Task 0 3 a: Consider the following Java program: public class PSuffix { static void countSamePrefixSuffix ( String s , int n ) {

Lab Task 03a:
Consider the following Java program:
public class PSuffix{
static void countSamePrefixSuffix(String s, int n)
{
// Stores the prefix string
String prefix ="";
for(int i =0; i < n -1; i++)
{
// Add the current character to the prefix string
prefix += s.charAt(i);
// Store the suffix string
String suffix = s.substring(n -1- i, n);
System.out.print("Proper prefix: "+ prefix +", Proper suffix: "+ suffix);
// Check if both the strings are equal or not
if (prefix.equals(suffix))
{
System.out.print("*"+ prefix.length());
}
System.out.println();
}
}
public static void main(String[] args)
{
String S = "ABCAABC";
int N = S.length();
countSamePrefixSuffix(S, N);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!