1. Print the two strings in alphabetical order. Assume the strings are lowercase. End with newline. Sample output:
capes rabbits
import java.util.Scanner;
public class OrderStrings {
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
String firstString;
String secondString;
firstString = scnr.next();
secondString = scnr.next();
/* Your solution goes here */
}
}
2. Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline.
import java.util.Scanner;
public class DetectWord {
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
String userString;
userString = scnr.next();
/* Your solution goes here */
}
}
import java.util.Scanner; public class OrderStrings { public static void main (String [] args) { Scanner scan = new Scanner(System.in); String firstString; String secondString; firstString = scan.next(); secondString = scan.next(); if(firstString.compareTo(secondString) < 0){ System.out.println(firstString+" "+secondString); } else{ System.out.println(secondString+" "+firstString); } } }
/////////////////////////////////////////////////////////////////////////////
import java.util.Scanner; public class DetectWord { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String userString; userString = scan.next(); if(userString.equals("Quit")){ System.out.println("Goodbye"); } else{ System.out.println("Hello"); } } }
Get Answers For Free
Most questions answered within 1 hours.