class Main { public static void main(String[] args) { java.util.Scanner scan = n
ID: 3742693 • Letter: C
Question
class Main {
public static void main(String[] args) {
java.util.Scanner scan = new java.util.Scanner(System.in);
System.out.println("Please type 'The quick brown fox.' in L33t");
String sentence = scan.nextLine();
// TODO: Compare the user's input against the L33t version.
String l33t = "Th3 q61ck br0wn f0x.";
boolean isSentenceMatching;
isSentenceMatching =
System.out.println("sentence = " + sentence);
System.out.println("l33t = " + l33t);
System.out.println("isSentenceMatching = " + isSentenceMatching);
}
}
Use the equals() method on the String class to compare the user's input against the l33t version of "The quick brown fox."
Remember that the simple l33t conversion we're using replaces
a -> 4
e -> 3
i -> 1
o -> 0
u -> 6
Output the input sentence, the l33t version, and the Boolean result of whether the two match.
NOTE: Look up String.equals on the Oracle Java documentation page for String. https://docs.oracle.com/javase/7/docs/api/java/lang/String.html
You can use it like this:
String first = "some text";
String second = "some other text";
boolean equals = first.equals(second);
Explanation / Answer
class Main { public static void main(String[] args) { java.util.Scanner scan = new java.util.Scanner(System.in); System.out.println("Please type 'The quick brown fox.' in L33t"); String sentence = scan.nextLine(); // TODO: Compare the user's input against the L33t version. String l33t = "Th3 q61ck br0wn f0x."; boolean isSentenceMatching; // comparing user input with the L33t version and storing in the boolean variable isSentenceMatching isSentenceMatching = sentence.equals(l33t); System.out.println("sentence = " + sentence); System.out.println("l33t = " + l33t); System.out.println("isSentenceMatching = " + isSentenceMatching); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.