Write a program that receives an integer as input, if the integer is even return 'even' else return 'odd'.
One-line condition with ternary operator
Determining if an integer is odd or even
Report a typo
Sample Input 1:
2Sample Output 1:
evenSample Input 2:
3Sample Output 2:
oddWrite a program in Java 25
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the input number
int number = scanner.nextInt();
// Write a one-line condition using ternary operator to check if the number is even or odd
// If the number is even, print "even"
// Otherwise, print "odd"
}
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.