Determine total number of ways of reaching a destination
Although this is not related to optimization, it looks like you could improve some of the ways you use loops.  If you're using a counter, chances are you should use a for loop:

for (int i = number; i &gt; 0; i--) { /*...*/ }


This works best if the loop counter initialization is pretty short.  But if it's too long and should remain on its own line, then instead have a while loop that updates the counter within the statement:

int i; // some long initialization here instead...

while (i-- &gt; 0) { /*...*/ }


First, I want to mention that you should use whitespace between operators and keywords for readability.  You use it in some places, but you should use it everywhere for consistency.

Second, non-empty code blocks should have the opening curly brace at the end of the line, not on the following line.  This is referenced in Google Java Style.

Instead of decrementing testCases within the loop:

while(testCases!=0)
{
    stationId = Integer.parseInt(br.readLine());
    ways[i++] = (short)(getWays(stationId)%(10^9 +7));
    testCases--;
}


have it done in the while loop statement:

while (testCases-- &gt; 0) {
    stationId = Integer.parseInt(br.readLine());
    ways[i++] = (short)(getWays(stationId)%(10^9 +7));
}


Instead of incrementing i within the loop:

while(i&lt;=n)
{
    sum+=(i-1);
    i++;
}


make it a for loop:

// move the initialization of i into the loop

for (int i = 1; i &lt;= n; i++) {
    sum += (i-1);
}


On another note, this:

short ways[]=new short[testCases],i=0;


should be on separate lines:

short ways[] = new short[testCases];
short i = 0;


Although they're of the same type, i is hard to see since it's crammed right next to ways[].