0% found this document useful (0 votes)
3 views

Program 1

The document outlines an assignment to determine if a number is even or odd using a simple algorithm. It includes a Java code snippet that prompts the user for an integer input and checks its divisibility by 2 to print 'Even' or 'Odd'. Example outputs for the inputs 10 and 11 are provided.

Uploaded by

macroff9932.ac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Program 1

The document outlines an assignment to determine if a number is even or odd using a simple algorithm. It includes a Java code snippet that prompts the user for an integer input and checks its divisibility by 2 to print 'Even' or 'Odd'. Example outputs for the inputs 10 and 11 are provided.

Uploaded by

macroff9932.ac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment No: 1 Date: 5/4/2024

Aim: To check if a number is even or odd.

Algorithm:

1. Take an integer input from the user.


2. Check if the number is divisible by 2.
3. If it is, print “Even”.
4. Otherwise, print “Odd”.

Code:
Import java.util.Scanner;

Public class EvenOdd {

Public static void main(Str Scanner scanner=new Scanner(System.in);


System.out.println(“Enter a number: “);

Int num = scanner.nextInt();

If (num % 2 == 0) {

System.out.println(“Even”);

} else {

System.out.println(“Odd”);

}
*Variable Description:*

- `num`: The integer input from the user.

*Output:*
```
Enter a number: 10
Even
```
Or
```
Enter a number: 11
Odd
```

Please note that I’m a text-based AI and cannot generate images. I hope this text-based
representation helps!

You might also like