| Operator and Expression | |||||||||||||||||||||||||||||||
| Boolean expressions and operations | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
| Example: | |||||||||||||||||||||||||||||||
| This program reads two numeric values from the user and displays the result of several comparisons involving the two numbers. | |||||||||||||||||||||||||||||||
| import java.util.*; import java.io.*; public class Aman { public static void main(String[] args) { // Variables for holding two numeric values entered by the user int x; double y; // Prompt for and read the two numeric values System.out.print("First number (integer): "); Scanner Keyboard=new Scanner(System.in); int x; x=Keyboard.nextInt((); System.out.print("Second number (floating-point): "); Scanner Keyboard=new Scanner(System.in); double y; y=Keyboard.nextDouble(); // Display information comparing the two values System.out.println(" " + x + " < " + y + " is " + (x "<" y)); System.out.println(" " + x + " <= " + y + " is " + (x <= y)); System.out.println(" " + x + " > " + y + " is " + (x > y)); System.out.println(" " + x + " >= " + y + " is " + (x >= y)); System.out.println(" " + x + " == " + y + " is " + (x == y)); System.out.println(" " + x + " != " + y + " is " + (x != y)); } } |
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||