The simplest line of code to test if the word "BASIC" is stored in the variable text1 is :
if ( text1 == "BASIC" ):
Step-by-step explanation:
- The simplest if-statement has two parts, a boolean "test" within parentheses ( ) followed by "body" block of statements within curly braces { }.
- The test can be any expression that evaluates to a boolean value true or false. The if-statement evaluates the test and then runs the body code only if the test is true.
- You should use the equals() method of the String class to compare Strings.
- == will do an object comparison between the strings in this situation, and although the value may be the same of the String objects, the objects are not the same.
- Equals: a == b. The double equals sign =. A single symbol a = b would mean an assignment