Java If condition with And, OR Operations demonstration with simple example


This example java program shows you how to use And, OR conditions in if conditions in Java


import java.util.Scanner;

public class IfConditionAndOrOperations {
	
	public static void main(String[] args) {
		System.out.println("please enter 1st number");

		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		in.close();

		System.out.println("please enter 2nd number");
		int y = in.nextInt();

		if (x > 0 && y > 0) {
			System.out.println("both  numbers are +ve");
			
		} else if (x > 0 || y > 0) {
			System.out.println("at least one number is +ve");

		} else {
			System.out.println("both  numbers are -ve");
		}
	}

}

Output:

please enter 1st number
4
please enter 2nd number
7
both  numbers are +ve