Respuesta :
Here you go,
Program:
import java.util.Scanner;
public class OrderStrings {
public static void main(String[] args) {
String firstString;
String secondString;
firstString = "rabbits";
secondString = "capes";
int status = firstString.compareTo(secondString);
if(status<0)
{
System.out.println(firstString + " " + secondString);
}
else
{
System.out.println(secondString + " " + firstString);
}
return;
}
}
Answer:
To print the two strings in alphabetical order if the strings are in lower case and end with a new line, first define a class and store the values in string variables. After this, compare the string using compareTo() function and finally print the result.
Further Explanation:
Code: Following is the JAVA code that prints the two strings in alphabetical order where strings are in lower case and end with new line.
import java.util.Scanner;
//definition of the class
public class StringOrder
{
public static void main(String[] args)
{
// define the variables
String firstString;
String secondString;
// assign values to the strings
firstString = "rabbits";
secondString = "capes";
// compare the strings
if(firstString.compareTo(secondString)<0)
{
System.out.println(firstString+""+secondString);
}
else
{
System.out.println(secondString+""+firstString);
}
return;
}
Learn more:
1. A company that allows you to license software monthly to use online is an example of ? brainly.com/question/10410011
2. Prediction accuracy of a neural network depends on _______________ and ______________. brainly.com/question/10599832
3. The shape of our galaxy was determined ‘on the inside looking out' by surveying the milky way using ____________ telescopes. brainly.com/question/7866623
4. List 3 characteristics of the ideal encryption scheme. https://brainly.com/question/3000161
Answer details:
- Grade: College Engineering
- Subject: Computer Science and Engineering
- Chapter: Java Programming
Keyword:
Java programming, python, C++, print, two strings, alphabetical order, lower case, upper case, output, capes rabbits, compare, loops, variables, first string, second string, scanner class