Main link: https://www.urionlinejudge.com.br/judge/en/problems/view/1074
URI Online Judge | 1074
Even or Odd
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Read an integer value N. After, read these N values and print a message for each value saying if this value isodd, even, positive or negative. In case of zero (0), although the correct description would be "EVEN NULL", because by definition zero is even, your program must print only "NULL", without quotes.
Input
The first line of input is an integer N (N < 10000), that indicates the total number of test cases. Each case is a integer number X (-107 < X <107)..
Output
For each test case, print a corresponding message, according to the below example. All messages must be printed in uppercase letters and always will have one space between two words in the same line.
Input Sample | Output Sample |
4 -5 0 3 -4 | ODD NEGATIVE NULL ODD POSITIVE EVEN NEGATIVE |
URI Online Judge |Solution 1074
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
int N, j;
Scanner input =new Scanner(System.in);
N =input.nextInt();
for (int i = 1; i <= N; i++) {
j = input.nextInt();
if (j == 0) {
System.out.print("NULL\n");
}else if(j % 2 != 0 && j < 0){
System.out.print("ODD NEGATIVE\n");
}else if(j % 2 != 0 && j > 0){
System.out.print("ODD POSITIVE\n");
}else if(j % 2 == 0 && j > 0){
System.out.print("EVEN POSITIVE\n");
}else{
System.out.print("EVEN NEGATIVE\n");
}
}
}
}
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks