Answer:
Step-by-step explanation:
import java.util.Scanner;
public class StringCompare {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String userInput;
userInput = scnr.nextLine();
if (userInput.endsWith("?")) {
System.out.println("A question");
} else {
System.out.println("Not a question");
}
}
}
In this code, we use the endsWith() method to check if the last character of the userInput string is a question mark. Based on the result, we output either "A question" or "Not a question".
Make sure to save the program with the filename "StringCompare.java" and compile and run it using a Java compiler or IDE.