Concatenate Strings Alphabetically JAVA - EASY - PART005
Concatenate Strings Alphabetically
Two string values S1 and S2 are passed as the input. The program must concatenate them depending on which string comes first in the alphabetical order.
PROGRAM IN JAVA:
*****************************************************************************
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
String s1=sc.nextLine();
if(s1.charAt(0)>=s.charAt(0))
System.out.print(s+s1);
else
System.out.print(s1+s);
}
}
*****************************************************************************
Comments
Post a Comment