English

Special Words Are Those Words that Start and End with the Same Letter. Examples: Existence Comic Window Palindrome Words Are Those Words Which Read the Same from Left to Right

Advertisements
Advertisements

Question

Special words are those words that start and end with the same letter.
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice versa
Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes. Write a program to accept a word check and print Whether the word is a palindrome or only a special word.

Code Writing
Advertisements

Solution 1

import java.util.Scanner;
class test
{
       public static void main ()
       {
            Scanner s = new Scanner (System.in);
            System.out.println ("Enter a word");
            String w = s.next ();
            int I = w.length ();
            string w1 = ""; char ch1, ch2;
 for (int k = 0; k < 1; k++)
{
        ch1 = w.charAt (k);
        w1 = chI + w1:
}
         if (w1. equals (w) == true)
         System.out.println ("It is  palindrome word");
         else if (w.charAt (0) == w.charAt (I - 1))
         System.out.println ("It is only a special word");
else
         System.out.println ("It is not a special word");
         }
}

shaalaa.com

Solution 2

// program to accept a word and print whether it is a special word or palindrome
import java.util.*;
public class SQ18
{ public static void main(String j[])
{ int i;
String rev = "", s;
System.out.println("Enter a WORD");
Scanner obj = new Scanner(System.in);
s = obj.next().trim(); // delete leading/trailing spaces in the input

for (i = s.length() − 1; i >= 0; i--) // decrement
rev = rev + s.charAt(i); // reverse of the word

if (s.equals(rev))
System.out.println("Palindrome word");
else if (s.charAt(0) == s.charAt(s.length() − 1)) // first and last character
System.out.println("Special word");
else
System.out.println("Not a special word or a Palindrome");
}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 4: String Handling - EXERCISES [Page 291]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 4 String Handling
EXERCISES | Q IX. 18. | Page 291

RELATED QUESTIONS

Design a class name ShowRoom with the following description :
Instance variables/ Data members :

String name – To store the name of the customer
long mobno – To store the mobile number of the customer
double cost – To store the cost of the items purchased
double dis – To store the discount amount
double amount – To store the amount to be paid after discount
Member methods: –
ShowRoom() – default constructor to initialize data members
void input() – To input customer name, mobile number, cost
void calculate() – To calculate discount on the cost of purchased items, based on following criteria

Cost Discount (in percentage)
Less than or equal to ₹ 10000 5%
More than ₹ 10000 and less than or equal to ₹ 20000 10%
More than ₹ 20000 and less than or equal to ₹ 35000 15%
More than ₹ 35000 20%

void display() – To display customer name, mobile number, amount to be paid after discount
Write a main method to create an object of the class and call the above member methods.


Give the output of the following string functions:

  1. "MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')
  2. "CABLE".compareTo("CADET") 

Give the output of the following string functions: 

  1. “ACHIEVEMENT”.replace(E’, ‘A’)
  2. “DEDICATE”.compareTo(“DEVOTE”)

Design a class Railway Ticket with following description: 
Instance variables/data members:
String name: To store the name of the customer
String coach: To store the type of coach customer wants to travel
long mob no: To store customer’s mobile number
int amt: To store a basic amount of ticket
int total amt: To store the amount to be paid after updating the original amount

Member methods
void accept (): To take input for a name, coach, mobile number and amount
void update (): To update the amount as per the coach selected

(extra amount to be added in the amount as follows)

Type of Coaches Amount
First_ AC 700
Second_AC 500
Third _AC 250
sleeper None

void display(): To display all details of a customer such as a name, coach, total amount and mobile number.

Write a main method to create an object of the class and call the above member methods. 


Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×