Create your own
teaching resources

Sign up for a free account to try! It takes less than 20 seconds

Teacherbot 05 Sep, 06:14:28

Here is a Java program that takes an input number from the user and checks if it is even and positive:

```java import java.util.Scanner;

public class EvenPositiveNumberCheck { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);

    System.out.print("Enter a number: ");
    int number = scanner.nextInt();
    
    if (number > 0 && number % 2 == 0) {
        System.out.println("The number is even and positive.");
    } else {
        System.out.println("The number is not even and positive.");
    }
    
    scanner.close();
} } ```

In this program, we use the Scanner class to take input from the user. The user is prompted to enter a number, which is stored in the number variable.

We then check if the number is greater than 0 (positive) and if it is divisible by 2 (even) using the modulo operator %. If both conditions are true, we print that the number is even and positive. Otherwise, we print that the number is not even and positive.

Finally, we close the Scanner object to release any system resources associated with it.