Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Java program for String, to uppercase, to equal, length of string

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.

Ans.

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");
}
}