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
kiruha [24]
3 years ago
4

// Problem 7: isPalindrome (10 points) // Return 1 if string s is palindrome. // Parse through the string to check if 1st char==

last char, 2nd char == (last-1) char, and so on.. // Return 1 if string is palindrome. Return 0 if string is not palindrome. // A palindrome is a sequence of characters which when reversed, is the same sequence of characters. // Palindrome string examples: rotor, noon, madam // Note: you may use reverseOneString() here but it is not necessary to use it.
Computers and Technology
1 answer:
vekshin13 years ago
5 0

Answer:

// program in java.

// library

import java.util.*;

// class definition

class Main

{

// recursive function to check palindrome

   public static int isPalindrome(String s)

   {

       // find length of String

       int len=s.length();

       for(int i=0;i<len;i++)

       {

           // compare first with last, second with second last and so on

           if(s.charAt(i)!=s.charAt(len-i-1))

           {

               // if not palindrome return 0

           return 0;

           }        

       }

       // if palindrome return 1

       return 1;

  }

  // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // object to read input

Scanner scr=new Scanner(System.in);

System.out.print("Enter a string:");

 // read string from user

String s =scr.nextLine();

 // call function to check palindrome

 int res=isPalindrome(s);

 // if string is palindrome

     if (res==1)

        System.out.println("Given String is a palindrome");

     else

     // if string is not palindrome

        System.out.println("Given String is not a palindrome");

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read a string from user and assign it to variable "s".Call the method isPalindrome() with parameter "s".In this function find the length of the string.Then compare first  character with last and second with second last and so on.If the string is palindrome then it will return 1 else it will return 0.

Output:

Enter a string:rotor                                                                                                      

Given String is a palindrome

 

You might be interested in
If you were able to earn interest at 3% and you started with $100, how much would you have after 3 years?​
erma4kov [3.2K]

109

A= Amount+ interest *sb

interest=P×r×t/100

100×3×3/100

100 cancel 100=3×3=$9

100+9=109

7 0
3 years ago
Lenders always accept applications for credit
LenKa [72]
The correct answer to the question that is being stated above is FALSE.

The statement is false because lenders do not always accept applications for credit. Lenders always consider credit history of the applicant. If the applicant has a good credit history background, then he qualifies.
3 0
4 years ago
What is text formatting?​
Ede4ka [16]

Answer:

Formatting text is the text that is displayed in a specified style. This refers to how text appears in your document. This includes the size, color, and font of the text.  

examples: text <em>text </em><u>text</u>

3 0
3 years ago
Read 2 more answers
How do I cancel and end my brainy subscription?
ella [17]

Answer:

Brainly Premium?

Explanation:

Go to your account, go to settings, and find the "cancel subscription" button in the *subscription* tab. Hope this helped!

7 0
3 years ago
Read 2 more answers
Loren Truesdale
LuckyWell [14K]

The output printed by the code is 18

<h3>The Code Analysis</h3>

The flow of the program is as follows:

  • The first line initializes a list of numbers named values
  • The second line initializes fred to 0
  • The third line is an iteration that is repeated for all numbers in the list
  • The next statement is a conditional statement that ensures that all 9's in the list are added, and saved in fred

<h3>The Code Computation</h3>

Recall that, the initial value of fred is 0, and there are 2 9's in the list.

So, the computation is:

fred=0 + 9 + 9

fred=18

This means that, the last instruction on line 10 will display 18, as the output

Hence, the output printed by the code is 18

Read more about algorithms at:

brainly.com/question/11623795

7 0
3 years ago
Other questions:
  • Let's say you're creating a search stream in your hootsuite dashboard, to find mentions of the phrase vacation holiday getaway.
    15·1 answer
  • What features do you think that a smart fridge should have? Please give me a quick answer! And in detail.
    13·1 answer
  • Where do you access the status report of an assigned task that is open?
    12·2 answers
  • What is the different between 32bit anf 64 bit verision​
    11·1 answer
  • In Excel, ____ is/are used to place worksheet, column, and row titles on a worksheet.
    11·1 answer
  • Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or
    10·1 answer
  • Write a method that accepts a string as an argument and returns a sorted string. For example, sort("acb") returns abc. Write a t
    6·1 answer
  • Which range function creates the following list of numbers?<br> 76 74 72 70 68 66 64 62
    11·1 answer
  • Cual de las siguientes es una desventaja del uso de las computadoras?
    5·1 answer
  • Please solve this in JAVA<br><br> Please see the attachment
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!