1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Juliette [100K]
4 years ago
13

Write a method that checks whether the input string or a sentence (a string with spaces) is a palindrome or not. The method shou

ld be case insensitive and should ignore spaces. Write a test program that prompts the user to input a string and invokes this method. Some example runs are: Enter the input string: madam Input string madam is a palindrome Enter the input string: banana Input string banana is NOT a palindrome Enter the input string: Race Car Input string Race Car is a palindrome Enter the input string: Too HOT to hoot Input string Too HOT to hoot is a palindrome
Computers and Technology
1 answer:
AURORKA [14]4 years ago
5 0

Answer:

import java.util.Scanner;

public class Pallindrome {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter the input string: ");

       String word = in.nextLine();

       System.out.println(isPallindrome(word));

   }

   public static String isPallindrome(String word){

       String rev ="";

       int len = word.length();

       for ( int i = len - 1; i >= 0; i-- )

           rev = rev + word.charAt(i);

       if (word.equals(rev))

           return word+" is palindrome";

       else

           return word+ " is not palindrome";

   }

}

Explanation:

  • Create the method in Java to receive a String parameter
  • Using a for loop reverse the string
  • Use another for loop to compare the characters of the original string and the reversed string
  • If they are equal print palindrome
  • else print not palindrome
  • Within the main method prompt user for a sentence
  • Call the method and pass the sentence entered by user
You might be interested in
Write a recursive method that takes four inputs: a 1-D array of Strings (i.e., exams), the length of this 1-D array (i.e., n), a
ale4655 [162]

Answer:

import java.util.*;

public class Main

{

       public static void main(String[] args)  

       {

           String [] exams = {"1;2;3;4;" , "5;6;7;8;" , "9;10;11;12;" };

           double[][] n = new double[exams.length][4];

           examArray = convert(exams , exams.length , 0 , n);

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

           {

               for(int j = 0 ; j < 4 ; j++)

               {

                   System.out.print(n[i][j] + "\t");

               }

              System.out.print("\n");

           }

       }    

       

/* recursive function convert defined here */

       public static double[][] convert(String[] exams , int number , int x , double [][] result)

       {

           if(x==number)

               return result;

           else

           {

               String total = exams[x];  

               String currentScore = "";

               int p = 0;

               for(int j = 0 ; j<totalScore.length() ; j++)

               {

                   char ch = total.charAt(j);/

                   if(ch==';')

                   {

                       result[x][p] = Double.parseDouble(currentScore);

                       p++;

                       currentScore = "";

                   }

                   else

                   {

                       currentScore = currentScore + Character.toString(ch);

                   }

               }

               return convert(exams , number , x+1 , result);

           }

           

       }

}

Explanation:

The Java source code defines a recursive function or method called convert that converts the results of three students that sat for four examinations to double or float number and screens their individual results for the four exams on the screen.

5 0
3 years ago
After the closing entries have been posted:
Nimfa-mama [501]
Closing entries are entries<span> made at the end of an accounting period to zero out all temporary accounts. The balances are transferred to permanent accounts. 
After the closing entries have been posted:
A. the temporary accounts are zeroed out
Revenues and expenses are transferred to the income Summary Account and then Income Summary is closed to Retained earnings.</span>
7 0
3 years ago
Check the devices that are external peripheral devices:
irina [24]

Answer:

Mouse, and keyboard

Explanation:

Common Sense

6 0
3 years ago
To back up your database, click the _____________to display Backstage view, click the Save &amp; Publish tab in the navigation b
Nuetrik [128]

Answer:

The answer is "File Tab".

Explanation:

In the database, restore is a database recovery process mechanism, that maintains administrative environment, configuration and stored software data. In the case of primary computer crashes, it helps to construct a new instance or to clone the database.

  • In this a file tab is an option, when we click on it is provides a backstage view of the file window, that deals with repositories and feature grades.
  • It helps you to do something in a database when you can make the situation within the database by putting commands on some other tabs on the Ribbon, that's why the file tab is the correct answer.
4 0
3 years ago
An administrator is having some trouble with a disk partition and needs to do maintenance on this partition but their user's hom
Anvisha [2.4K]

Answer:

Option B.

Explanation:

init 1 command is used to fulfill the requirement mentioned above.

4 0
3 years ago
Other questions:
  • Write code that prints: Ready! firstNumber ... 2 1 Run!
    12·1 answer
  • A(n) __________________ device is a breath analyzer on your vehicle that is electronically connected to the ignition.
    11·1 answer
  • Network id is 192.168.10.32/28. what would be the ip address, if you assign the last available ip address in the range
    14·2 answers
  • Imagine a situation where two developers are simultaneously modifying three different software components. what difficulties mig
    11·1 answer
  • Kerrri uses a database file many time a day. To increase her productivity, she should___.
    15·1 answer
  • Rite a c++ function, smallestindex, that takes as parameters an int array and its size and returns the index of the first occurr
    15·1 answer
  • What message would you have gotten if your computer became infected with the elk cloner virus?
    7·1 answer
  • Using javaFX components
    6·1 answer
  • Assume that passwords are selected from four-character combinations of 26 alphabeticcharacters. Assume that an adversary is able
    11·1 answer
  • John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastructure issues.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!