मराठी

Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length - Computer Applications

Advertisements
Advertisements

प्रश्न

Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length or print the message both the strings are of equal length.

थोडक्यात उत्तर
Advertisements

उत्तर

import java.util.*;
public class Strings 
{
     public static void main( String [] args)
     {
        String s1 ="" ,s2=""; 
        Scanner sc=new Scanner(System.in); 
        System.out.println("Enter two strings:");
        s1=sc.nextLine();
        s2=sc.nextLine(); 
        s1=s1.toUpperCase(); 
        s2=s2.toUpperCase(); 
        if (!s1.equals(s2))
        {
             if (s1.length()>s2.length())
                  System.out.println(s1); 
            else
                  System.out.println(s2);
        }
       else
       System.out.println("Strings are equal");
    }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2021-2022 (March) Set 1

संबंधित प्रश्‍न

Write the return data type of the following function:

endsWith( )


Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for the name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display “Sorry Not Found!”. 
Seven wonders — CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations — MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example

Country Name: INDIA     Output: INDIA-TAJMAHAL
Country Name: USA        Output: Sorry Not Found!


Give the output of the following string methods.

"MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')


The String class method to join two strings is ______.


The output of the function "COMPOSITION". substring(3, 6):


Give the output of the following String class method:

"COMMENCEMENT".lastIndexOf('M')

Give the output of the following String class method:

"devote". compareTo("DEVOTE")

Define a class to accept a String and print the number of digits, alphabets and special characters in the string.

Example: S = "KAPILDEV@83"
Output: Number of digits - 2 '
Number of Alphabets - 8
Number of Special characters - 1

The following code to compare two strings is compiled, the following syntax error was displayed - incompatible types - int cannot be converted to boolean.

Identify the statement which has the error and write the correct statement. Give the output of the program segment.

void calculate()
  {
  String a="KING",b="KINGDOM";
  boolean x=a.compareTo(b);
  system.out.println(x);
  }

Write the output of the following String methods:

String x="Galaxy",y="Games";
(a)  System.out.println(x.charAt(0)==y.charAt(0));
(b)  System.out.println(x.compareTo(y));

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×