using java code
Create a program that has a main method and a recursive method:
isPalindrome – recursive method that will receive a String and will return a Boolean that will evaluate whether the String is a palindrome or not.
The main method will also ask the user for a word/phrase and using the recursive method isPalindrome it will print a message whether the word/phrase is a palindrome or not.
//PalindromeRecursion.java
import java.util.Scanner;
public class PalindromeRecursion {
private static boolean isPalindrome(String str){
if(str==null || str.length() == 0 || str.length() == 1){
return true;
}
else{
if(str.charAt(0) == str.charAt(str.length()-1)){
return isPalindrome(str.substring(1,str.length()-1));
}
else{
return false;
}
}
}
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = scanner.nextLine();
if (isPalindrome(str)) {
System.out.println(str + " is palindrome");
} else {
System.out.println(str + " is not palindrome");
}
}
}
using java code Create a program that has a main method and a recursive method: isPalindrome...
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...
You need to write a program (one java class containing Main calling function isPalindrome (String str). The function isPalindrome (returns Boolean T/F) needs to determine whether or not a string is a palindrome, using recursion. The algorithm to check whether a string is a palindrome is shown below: /* check for first and last char of String: * if they are same then do the same thing for a substring * with first and last char removed. and carry on...
IN JAVA. Implement a method, public static boolean isPalindrome(String) to determine whether the specified String is a palindrome or not. A palindrome is a phrase that reads the same forwardand backward; not including punctuation, spaces, or letter case. Some example palindromes include: Just the method please..
Create a Java program that uses methods. In the main method, the program must prompt the user for a Social Security Number in the following format: DDD-DD-DDDD, where D is a digit. The program must call a method called “validate” that must receive the inputted SSN from the main method and decide whether the inputted number is valid and return the decision to the main method. Then, the main method must print the decision.
Please write in java
Write a main program that runs the following two recursive methods demonstrating that they work. #1) Write a recursive method writeSquares that accepts an integer n and prints the first n squares with the odd squares in decending order, followed by the even squares in acending order. For example • writeSquares(8): prints . 49 25 9 1 4 16 36 64 • writeSquares(11); prints 121 81 49 25 9 1 2 16 36 64 100 •...
In java, write a program with a recursive method which asks the user for a text file (verifying that the text file exists and is readable) and opens the file and for each word in the file determines if the word only contains characters and determines if the word is alpha opposite. Now what I mean by alpha opposite is that each letter is the word is opposite from the other letter in the alphabet. For example take the word...
Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following strings: madam, abba, 22, 67876, 444244, trymeuemyrt Modify the function isPalindrome of Example 6-6 so that when determining whether a string is a palindrome, cases are ignored, that is, uppercase and lowercase letters are considered the same. The isPalindrome function from Example 6-6 has been included below for your convenience. bool isPalindrome(string str) { int length = str.length(); for (int i...
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion { public static void main(String[] args) { Recursion r = new Recursion(); System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true } public Boolean isPalindrome(int num){ return false;...
PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...
Complete the printPalindrome method in the provided Palindrome.java program. The printPalindrome method accepts a String as a parameter and prints whether the parameter String is a palindrome (i.e., reads the same forwards as it does backwards, for example, "abba" or "racecar"). Make the code case-insensitive, so that words like "Abba" and "Madam" will be considered palindromes. import java.util.*; /** * Determines if a user entered String is a palindrome, which means the String * is the same forward and reverse....