Computer Science, asked by gaurav244, 1 year ago

Computer class 9 java

Attachments:

Answers

Answered by Sahil1711
0
#include <iostream> using namespace std; int main() { int n; cout << "Enter an integer: "; cin >> n; if ( n % 2 == 0) cout << n << " is even."; else cout << n << " is odd."; return 0; }

Output

Enter an integer: 23 23 is odd.

In this program, if..else statement is used to check whether n%2 == 0 is true or not. If this expression is true, n is even if not n is odd.

You can also use ternary operators ?:instead of if..else statement. Ternary operator is short hand notation of if...else statement.
mark as brainliest

gaurav244: hi yll
Answered by shashwat14
1
class oddoreven
{
public static void main(int i)
{
if(i%2==0)
{
System.out.println("Even");
}
else
{
System.out.println("odd");
}
}
}
Similar questions