Welcome to Westonci.ca, the Q&A platform where your questions are met with detailed answers from experienced experts. Discover a wealth of knowledge from experts across different disciplines on our comprehensive Q&A platform. Explore comprehensive solutions to your questions from a wide range of professionals on our user-friendly 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.
Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Thank you for using Westonci.ca. Come back for more in-depth answers to all your queries.