Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class comparisons
- {
- public static void main(String[] args)
- {
- int num1 = 1; //int1 is a number type
- String str1 = "1"; //str1 is a word, the "1" is treated as a symbol, not as a number
- System.out.println(num1 == 1);
- //Use == to compare primitive types, like ints, booleans and doubles
- // System.out.println(str1 == 1);
- // System.out.println(num1.equals("1"));
- System.out.println(str1.equals("1"));
- //Use .equals to compare object, or more commonly, strings
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement