Ruang penulis
← Kembali ke jurnal
Basic

How do I use the boolean negation (!) operator in Java?

The ! operator is a logical compliment operator. The operator inverts the value of a boolean expression. package org.kodejava.basic; public class NegationOperator { public static void main(String[] args) { // negate the result of boolean expressions boolean negate = !(2 < 3); boolean value = !false; System.out.println("result: " + negate); System.out.println("value : " + value); […]

DWayan · 26 Okt 2010 · 1 menit baca

Artikel oleh Wayan · Sumber: Kode Java ↗

Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.

The ! operator is a logical compliment operator. The operator inverts the value of a boolean expression.

package org.kodejava.basic;

public class NegationOperator {
    public static void main(String[] args) {
        // negate the result of boolean expressions
        boolean negate = !(2 < 3);
        boolean value = !false;

        System.out.println("result: " + negate);
        System.out.println("value : " + value);
    }
}

Here is the result of the program:

result: false
value : true
← Jelajahi catatan lainnya