Write a program that includes the following three functions

Write a program that includes the following three functions, making sure each is clearly exercsied within your program:

a. IsPalindrome: This funciton returns true if the cString parameter is a palindrome, false if it is not. As you have seen, a palindrome is any group of characters (i.e., a word) that appears the same when written forward and backward.

b. IsAlphaStr: A function that returns true if the cString you pass it contains all alphabetic characters. If the parameter does not contain all alpha characters, the function returns false. Feel free to use the isalpha function we discussed earlier.

c. CountChar: A function to simply count and return the number of times a specific character occurs in a cString. This function will take two parameters: the cString to check and the specific character you are looking for.

Solution

Here are the 3 functions:

1. To check if the string is a palindrome.

import java.util.Scanner;
public class palindrome {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       String originalString, reverseString = \"\";
   Scanner in = new Scanner(System.in);
     
   System.out.println(\"Enter a string to check if it is a palindrome\");
   originalString = in.nextLine();
     
   int length = originalString.length();
     
   for ( int i = length - 1; i >= 0; i-- )
   reverseString = reverseString + original.charAt(i);
     
   if (originalString.equals(reverseString))
   System.out.println(\"Entered string is a palindrome.\");
   else
   System.out.println(\"Entered string is not a palindrome.\");
   }

}

2. To check if the String contains all alphabets

import java.util.Scanner;
public class isAlpha {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       String original = \"\";
       Scanner in = new Scanner(System.in);
         
   System.out.println(\"Enter a string to check if it contains all alphabetic characters\");
   original = in.nextLine();
  
   if(original.matches(\"[a-zA-Z]+\")){
       System.out.println(\"Entered string contains all characters.\");
   }else{
       System.out.println(\"Entered string does not contain all characters.\");
   }
   }
}

3. To check the count of a character in a string

import java.util.Scanner;
public class countChar {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       String original,subStr = \"\";
       int counter = 0;
         
       Scanner in = new Scanner(System.in);
         
   System.out.println(\"Enter a target string\");
   original = in.nextLine();
   System.out.println(\"Enter the character to be found\");
   subStr = in.nextLine();
     
  
   for( int i=0; i<original.length(); i++ ) {
   if( original.charAt(i) == subStr.charAt(0)) {
   counter++;
   }
   }
   System.out.println(\"Entered Characer appears \"+ counter + \" times in the enetered string.\");
   }
}

Write a program that includes the following three functions, making sure each is clearly exercsied within your program: a. IsPalindrome: This funciton returns t
Write a program that includes the following three functions, making sure each is clearly exercsied within your program: a. IsPalindrome: This funciton returns t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site