This code compares text entered by the user (userText) with a keyword (endProgram). When the user enters the word exit, the program will complete and close.
public static void main(String[] args) {
String endProgram = "exit";
String userInput;
java.util.Scanner input = new java.util.Scanner(System.in);
do {
userInput = input.nextLine();
} while ( !(userInput.equals(endProgram)) );
}
Is there a better way to write the code within the while parenthesis?
That is, instead of using !(String.equals(String)) is there another function to compare inequality?
Considering that ! is just one character, there's not much point in having a separate inequality test function that would just return the negation of the equality function.
So no.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With