Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to use logical operators in Java

1 Answer

0 votes
public class Example {
    public static void main(String[] args) {
        int a = 1;
        int b = 2;
  
        if ((a == 1) && (b == 2)) {
            System.out.println("a = 1 AND (&&) b = 2");
        }
        if ((a == 1) || (b == 1)) {
            System.out.println("a = 1 OR (||) b = 1");
        }
        if (a != b && b == 2) {
            System.out.println("a != b AND (&&) b == 2");
        }
        if (a > b || b == 2) {
            System.out.println("a > b OR (||) b == 2");
        }
        if ( !(a > b) ) {
            System.out.println("!(a > b)");
        }
    }
}
   
   
   
   
/*
run:
   
a = 1 AND (&&) b = 2
a = 1 OR (||) b = 1
a != b AND (&&) b == 2
a > b OR (||) b == 2
!(a > b)
   
*/

 



answered Jan 12, 2016 by avibootz
edited Aug 13, 2022 by avibootz

Related questions

1 answer 121 views
121 views asked Oct 12, 2022 by avibootz
1 answer 114 views
114 views asked Aug 13, 2022 by avibootz
1 answer 111 views
111 views asked Aug 13, 2022 by avibootz
1 answer 151 views
1 answer 177 views
1 answer 175 views
1 answer 161 views
161 views asked Nov 7, 2015 by avibootz
...