Logical Operators

Java provides Logical Operator that may be used to form complex conditions for control structures by combining simple conditions. The logical operators(symbolic representation) are &&( logical AND), &(Boolean  Logical  AND),||(Logical OR), |(Boolean logical inclusive OR).^(Boolean logical exclusive OR) and !(logical NOT,also called logical negation operator)

/*Logical Operators in Java Swing*/

import javax.swing.*;

public class Logical_Operator

  {

       public static void main(String aba[])

           {

              JTextArea outputArea=new JTextArea(20,30);

             JScrollPane scoller=new JScrollPane(outputArea);

             String output="";

            output+="Logical AND (&&)"+

                             "\n\tResultt(false && false)::" + (false&&false) +

                             "\n\tResultt(false && true)::" + (false&&true) +

                             "\n\tResultt(true && false)::" + (true&&false) +

                             "\n\tResultt(true && true)::" + (true&&true);

            output+="\n\nLogical OR (||)"+

                             "\n\tResultt(false || false)::" + (false||false) +

                             "\n\tResultt(false || true)::" + (false||true) +

                             "\n\tResultt(true || false)::" + (true||false) +

                             "\n\tResultt(true || true)::" + (true||true);

         

           

            output+="\n\nBoolean Logical AND (&)"+

                             "\n\tResultt(false & false)::" + (false&false) +

                             "\n\tResultt(false & true)::" + (false&true) +

                             "\n\tResultt(true & false)::" + (true&false) +

                             "\n\tResultt(true & true)::" + (true&true);  

         output+="\n\nBoolean Logical inclusive OR (|)"+

                             "\n\tResultt(false | false)::" + (false|false) +

                             "\n\tResultt(false | true)::" + (false|true) +

                             "\n\tResultt(true | false)::" + (true|false) +

                             "\n\tResultt(true | true)::" + (true|true);  

        output+="\n\nBoolean Logical exclusive OR (^)"+

                             "\n\tResultt(false ^ false)::" + (false^false) +

                             "\n\tResultt(false ^ true)::" + (false^true) +

                             "\n\tResultt(true ^ false)::" + (true^false) +

                             "\n\tResultt(true ^ true)::" + (true^true);  

      output+="\n\n Logical NOT (!)"+

                             "\n\tResultt(!false)::" + (!false) +

                             "\n\tResultt(! true)::" + (!true) ;

                             

 outputArea.setText(output);

 JOptionPane.showMessageDialog(null,scoller,

                      "Truth Tables", JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}

  Output....       

Logical Operator in Java Swing

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @