Sunday, 17 June 2018

Logical operator show at GUI java program


There are two logical operators available in java. java uses && for the logical "AND" operator and || for the logical "OR" operator.use the logical operators to combine the result of Boolean expressions.
here we provided a java source code show logical operators
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaprogram;

import javax.swing.*;
/**
 *
 * @author rajesh kumar shukla
 */
//Demonstrating the logical operators
public class LogicalOperators {
  
     public static void main( String args[] )
         {
         JTextArea outputArea = new JTextArea( 17, 20 );
         JScrollPane scroller = new JScrollPane( outputArea );
         String output = "";
        
         output += "Logical AND (&&)" +
         "\nfalse && false: " + ( false && false ) +
         "\nfalse && true: " + ( false && true ) +
         "\ntrue && false: " + ( true && false ) +
         "\ntrue && true: " + ( true && true );
        
         output += "\n\nLogical OR (||)" +
         "\nfalse || false: " + ( false || false ) +
         "\nfalse || true: " + ( false || true ) +
         "\ntrue || false: " + ( true || false ) +
         "\ntrue || true: " + ( true || true );
        
         output += "\n\nBoolean logical AND (&)" +
         "\nfalse & false: " + ( false & false ) +
         "\nfalse & true: " + ( false & true ) +
         "\ntrue & false: " + ( true & false ) +
         "\ntrue & true: " + ( true & true );
        
         output += "\n\nBoolean logical inclusive OR (|)" +
         "\nfalse | false: " + ( false | false ) +
         "\nfalse | true: " + ( false | true ) +
         "\ntrue | false: " + ( true | false ) +
         "\ntrue | true: " + ( true | true );
        
         output += "\n\nBoolean logical exclusive OR (^)" +
         "\nfalse ^ false: " + ( false ^ false ) +
         "\nfalse ^ true: " + ( false ^ true ) +
         "\ntrue ^ false: " + ( true ^ false ) +
         "\ntrue ^ true: " + ( true ^ true );
        
         output += "\n\nLogical NOT (!)" +
         "\n!false: " + ( !false ) +
         "\n!true: " + ( !true );
        
         outputArea.setText( output );
         JOptionPane.showMessageDialog( null, scroller, "Truth Tables", JOptionPane.INFORMATION_MESSAGE );
         System.exit( 0 );
     }
}

0 comments:

Post a Comment