Tiling problem...why this code not working

import java.util.*;

public class Main
{
static int count(int n,int m)
{
int ways[] = new int[n + 1];
ways[0] = 0;
int i;
for (i = 1; i <= n; i++)
{
if (i > m)
ways[i] = ways[i - 1] + ways[i - m];

        else if (i < m || i == 1)
            ways[i] = 1;

        else
            ways[i] = 2;
    }
    return ways[n];
}


public static void main(String[] args) 
{
       Scanner sc=new Scanner(System.in);
	int test=sc.nextInt();
	for(int i=0;i<test;i++)
	{
		int n=sc.nextInt();
		int m=sc.nextInt();
		System.out.print(count(n,m));
	}
}

}

@tishachhabra2702_8fc5a68a2e295e35 FIrst of all when you’re printing
System.out.print(count(n,m));
use println instead of print.
Another problem is with your code is that the no. ways can be very very large so instead of using int array use long array.
There can also be the case where even long cannot store the answer so in every iteration of your for loop take modulo by 10^9+7(It is also mentioned in question to take modulo and then give answer).
Corrected Code :

import java.util.*;

public class Main
{
static long count(int n,int m)
{
long ways[] = new long[n + 1];
ways[0] = 0;
int i;
for (i = 1; i <= n; i++)
{
if (i > m)
ways[i] = ways[i - 1] + ways[i - m];

        else if (i < m || i == 1)
            ways[i] = 1;

        else
            ways[i] = 2;
		
		ways[i] %= 1000000007;
    }
    return ways[n];
}


public static void main(String[] args) 
{
       Scanner sc=new Scanner(System.in);
	int test=sc.nextInt();
	for(int i=0;i<test;i++)
	{
		int n=sc.nextInt();
		int m=sc.nextInt();
		System.out.println(count(n,m));
	}
}
}

Thankyou the codenot get through all test cases.

Thankyou the code now get through all test cases. But i didn’t understand why we took modulo, please explain.

@tishachhabra2702_8fc5a68a2e295e35 We took module bcoz no. of ways can be that large which cannot be stored in long also. So to store it in long we have to take modulo by 10^9+7