Contoh penggunaan operator logika


public class Logika
{
public static void main (String[ ] args)
{
int x = 5; // pendefinisian variabel
int y = 3;
int z = 1;
boolean nilai;

System.out.println (“x = 5, y = 3, z = 1”);
nilai = (x > y && z == 1);
System.out.println (“x > y && z == 1 ” + nilai);
nilai = (x > y || z > 5);
System.out.println (“x > y || z > 5 ” + nilai);
nilai = ( ! (z == 1));
System.out.println (“! (z == 1)) ” + nilai);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s