Advertisement
MrPinzon

Untitled

May 13th, 2022
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public class comparisons
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         int num1 = 1; //int1 is a number type
  6.         String str1 = "1"; //str1 is a word, the "1" is treated as a symbol, not as a number
  7.  
  8.         System.out.println(num1 == 1);
  9.         //Use == to compare primitive types, like ints, booleans and doubles
  10. //        System.out.println(str1 == 1);
  11. //        System.out.println(num1.equals("1"));
  12.         System.out.println(str1.equals("1"));
  13.         //Use .equals to compare object, or more commonly, strings
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement