The compiler i use compiles the program fine and it shows correct results for sample inputs shown in the question and also for my custom inputs. However, my program is giving wrong output as per the website. Please tell me the errors in my program.
My program is as follows: for odd-even problem
import java.util.Scanner;
public class practicequestion5
{
public static void main(String args[])
{
Scanner scn = new Scanner(System.in);
int N = scn.nextInt();
while(N>0)
{
long cars = scn.nextInt();
int i=0, j=0, k=0;
long numref1 = cars, numref2 = cars;
int index=0;
while(numref1>=10)
{
numref1=numref1/10;
index++;
}
// System.out.println("index = "+index);
long power=1, r=0, q=0;
long [] store = new long[index+1];
for(i=index;i>=0;iā)
{
power=1;
j=i;
while(j>0)
{
power*=10;
jā;
}
// System.out.println("power = "+power);
q = numref2/power;
r = numref2%power;
store[index-i]=q;
numref2 = r;
// System.out.println("q = ā+q+ā, r = "+r);
}
long odd=0,even=0;
for(i=0;i<index+1;i++)
{
if((i)%2==0)
{
even+=store[i];
}
else
{
odd+=store[i];
}
}
// System.out.println("even = "+even+"odd = "+odd);
if((even%4==0)||(odd%3==0))
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}
N--;
}
}
}
(print statements commented in the program were used by me when i was debugging it)
Also, please tell me what inputs does the website give for this problem.