answer.
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]
2 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:
vekshin12 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
What types of messages flow across an SDN controller’s northbound and southbound APIs? Who is the recipient of these messages se
Marta_Voda [28]

Answer and Explanation:

Messages flow across an SDN controller's:  

Northbound APIs:  

• Messages which help in read/write state of the network and developing flow tables within the  

state management layer.  

• Notifications for the state-change events.  

• The interaction between the controller and network control applications is done through the  

northbound interface.  

• Network control applications send messages to the controller.  

Southbound APIs:  

• Messages which help for the up-to-date view of the network's state like message for the  

attached link has gone up or down, new devices are joined the network, or indications of the  

device is up or down.  

• Controller's southbound interface is the communication among the controller and the controlled  

devices. Controlled devices are the recipients of the messages sent form the controller.  

3 0
2 years ago
You have several pictures of different sizes that you would like to frame.A local picture framing store offers two types of fram
exis [7]

Answer:

written in java

Note :  Package name was excluded

 

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       //declared 8 uninitialised variable  

       String input;

       double cost, colorC, frameC, paperC, glassC, crownC;

       char crowns;

       int type, color, crown, length, width, area, perimeter;

       

       //creating an instance of the Scanner class to accept value from user

       Scanner scanner = new Scanner(System.in);

       System.out.print("Enter length of frame: ");

       length = scanner.nextInt();

       System.out.print("Enter width of frame: ");

       width = scanner.nextInt();

       System.out.print("Do you want a fancy frame or a regular frame\nEnter 1 for fancy, 2 for regular: ");

       type = scanner.nextInt();

       if (type == 1) {

           frameC = 0.25;

       } else {

           frameC = 0.15;

       }

       System.out.print("Do you want a white frame or a colored frame\nEnter 1 for white, 2 for colored: ");

       color = scanner.nextInt();

       if (color == 2) {

           colorC = .10;

       } else{

           colorC = 0;

       }

       System.out.print("Do you want crowns \nEnter y for yes, n for no ");

       input = scanner.next();

       crowns = input.charAt(0);

       if (crowns == 'y' || crowns == 'Y') {

           System.out.print("How many crowns?");

           crown = scanner.nextInt();

       } else

           crown = 0;

       if (crown > 0)

           crownC = crown * .35;

       else

           crownC = 0;

       area = length * width;

       perimeter = length * 2 + width * 2;

       paperC = area * .02;

       glassC = area * .07;

       cost = glassC + paperC + crownC + colorC * perimeter + frameC * perimeter;

       System.out.println("The cost of your frame is: $" + cost);

   }

}

5 0
2 years ago
. When you have multiple graphics positioned on a page, you can _______________ them so that they are a single graphic instead o
alisha [4.7K]
The best answer is B
i hope its help
8 0
2 years ago
Some numbers are formed with closed paths. the digits 0, 4, 6 and 9 each have 1 closed path and 8 has 2. None of the other numbe
postnew [5]

Answer:

def cal(n):

s=0

while n>0:

r=n%10

if(r==0 or r==4 or r==6 or r==9):

s=s+1

elif r==8:

s=s+2

n=n//10

print(s)

n=int(input("enter number:"))  

print(n)

cal(n)

Explanation:

  • Create a function to calculate count of closed path .
  • Create a variable to store count of closed path .
  • While number is positive , extract last digit of n .
  • Reduce number by truncating last digit .
  • Make a function call to compute count of path.
5 0
2 years ago
To gain experience of using and combing different sorting algorithms: election sort, insertion sort, merge sort, and quick sort.
ch4aika [34]

Answer:

Motivation? The search problem.

Sorting algorithms: insertion sort, shellsort, heapsort, mergesort, quicksort, bubblesort

At the very least, "general purpose" sorting algorithms require O(n log n) comparisons

Explanation:

3 0
2 years ago
Other questions:
  • The part of the computer that contains the brain, or central processing unit, is also known as the A.monitor B.modem C.keyboard
    10·1 answer
  • Hybrid processors that can process 32 bits or 64 bits are known by what term?
    8·1 answer
  • Which of the following statements about crane hand signal training are true? A. Both statements are true about crane hand signal
    5·1 answer
  • Letitia is in high school. She wants to go to medical school in Kentucky and then become a pediatric surgeon to help children. W
    5·2 answers
  • In cell B16, enter a function to calculate the total attendance for the years 2014 through 2018 using the totals in the range B1
    10·1 answer
  • Alyosha was explaining to a friend the importance of protecting a cryptographic key from cryptoanalysis. He said that the key sh
    10·1 answer
  • A large Internet merchandise provider determines its shipping charges based on the number of items purchased. As the number incr
    6·1 answer
  • What is the function of napier's bones<br>​
    8·1 answer
  • Draw a flowchart and write the algorithm to find even number between 1 to 50​
    7·1 answer
  • Spark is electrical discharge in air, while air is mix of variety of gases what particles conduct electricity in gas
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!