Discover the answers you need at Westonci.ca, a dynamic Q&A platform where knowledge is shared freely by a community of experts. Our platform provides a seamless experience for finding reliable answers from a knowledgeable network of professionals. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.
Sagot :
Answer:
Following are the code to the given question:
import java.util.Scanner;//import package
public class OrderStrings // defining a class OrderStrings
{
public static void main(String[] args) //defining a main method
{
Scanner scnr = new Scanner(System.in);//defining a Scanner class object
String firstString;//defining a String variable
String secondString; //defining a String variable
firstString = scnr.next();//input value
secondString = scnr.next();//input value
if (firstString.compareTo(secondString) < 0)//use if to compare sting value
System.out.println(firstString + " " + secondString);//print sting value
else//else block
System.out.println(secondString + " " + firstString);//print sting value
}
}
Output:
rabbits capes
capes rabbits
Explanation:
In this code a class "OrderStrings" is defined inside the class the main method is defined that declares the two string variable that uses the input method to input the string value and after input, it uses the conditional statement. Inside this compareTo method is declared that compare string value and prints the string value.
We appreciate your visit. Hopefully, the answers you found were beneficial. Don't hesitate to come back for more information. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.