Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a void method called palindromeCheck that takes NO argument. The method sh

ID: 3603423 • Letter: W

Question

Write a void method called palindromeCheck that takes NO argument. The method should have functionality to check whether or not the word is a palindrome and print to the screen all of the palindromes, one per line. (java)

This program reads words, identifies, counts and writes all the palindromes and the total t palindrome count public static void palindromeCheck) String someword = "" ". int count = 0 int total = 0 // keeps track of Palindrome words only (define algorithm to count # of palindrome words / Counts the total number of lines read from the given text file System.out.println(" Enter some words separated by white space") // declare your Scanner object here Scanner keyboard new Scanner (System.in); // hint 1: Using keyboard.next() will only return what comes before a space // hint 2: Using keyboard.nextLine() automatically reads the entire current line for each word user enters while (keyboard.hasNext()) someWord = keyboard.next(); // store each word in a string variable and then do your operations / increment number of words as you read each one total++ // #1. Code your logic for how to determine if a word is Palindrome first, then complete # 2 System.out.println("total+someWord) // test // if encountered ENTER then close scanner stream and terminate keyboard.close(): /Ix is a variable for count and y is variable total // #2, print "There are x palindromes out of y words

Explanation / Answer

import java.util.Scanner;

public class PalindromeCheck

{

public static void palindromeCheck()

{

String someWord=" ";

int count=0;

int total=0;

System.out.println("Ënter some words entered by whitespace");

Scanner keyboard =new Scanner(System.in);

String[] words=keyboard.nextLine().split(" ");

for(int i=0;i<words.length;i++)

{

boolean flag=true;

int l=words[i].length();

for(int j=0;j<=l/2;j++)

{

if(words[i].charAt(j)!=words[i].charAt(l-j-1))

{

flag=false;

break;

}

}

if(flag)

count++;

}

System.out.println("There are "+count+" palindromes out of "+words.length+" words");

keyboard.close();

}

public static void main(String[] args)

{

palindromeCheck();

}

}

Output

Ënter some words entered by whitespace
This ii a malayalam.
There are 3 palindromes out of 4 words

please do give the answer a thumbs up and leave a comment in case of any doubts.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote