I am getting the correct output for all the cases .
but as soon as I submit my code , it shows an error.
Delhi's Odd Even
share your code here
import java.util.Scanner;
import java.lang.Math;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int num[] = new int[1000000000] ;
int cars = sc.nextInt();
if(cars>0&&cars<=1000)
{
for(int i = 0 ; i<cars ; i++)
{
num[i] = sc.nextInt();
}
}
for(int j = 0 ; j <cars ; j++)
{
if(num[j]<0)
{ System.out.println(“No”);
}
else
{
int n = (int)Math.log10(num[j]) + 1;
int sum = 0 , tmp = num[j];
for(int i =1;i<=n;i++)
{
int rem = tmp%10;
sum = sum + rem;
tmp = tmp/10;
}
if((sum%2==0)&&(sum%4==0))
{
System.out.println("Yes");
}
if((!(sum%2==0))&&(sum%3==0))
{
System.out.println("Yes");
}
else
System.out.println("No");
}
}
}
}
see first of all we dont have to check for constraints…just take the input as specified in the ques…
So far
Is there any error in the code
you have to calculate 2 sums
1 of even digits and other of odd digits
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.