Why my Test cases are not be passed but output is true
Delhi's Odd Even
Hey @shardul15
your logic is wrong
- Take input of the Number.
- Declare two variables to store the sum of even numbers and odd numbers.
- Extract digit one by one ( by % 10).
-
Check if the number is even or odd.
-
If even add the number in the variable storing even sum.
-
- Othewise add it in the variable storing odd sum.
- After the loop, Check if the even sum is divisible by 4 || if the odd sum is divisible by 3.
-
If True, print Yes.
-
otherwise print No.
-
@Monu-Singh-480654572341490 My logic is same as you said
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
if (n <= 1000) {
while (n > 0) {
int num = scn.nextInt();
if (num >= 0 && num <= 1000000000) {
int esum = 0;
int osum = 0;
while (num > 0) {
int rem = num % 10;
if (rem % 2 == 0) {
esum += rem;
} else {
osum += rem;
}
num = num / 10;
}
if (esum % 4 == 0 || osum % 3 == 0) {
System.out.println("Yes");
} else {
System.out.println("NO");
}
}
n--;
}
}
}
}
System.out.println(“No”); instant of System.out.println(“NO”);
1 Like