Java.util.NoSuchElement Exception

import java.util.Scanner;
class Codechef
  public static void main (String[] args)
   Scanner in=new Scanner(;
   int T= in.nextInt();

   for(int k=0;k<T;)
     int M=in.nextInt();
     int N=in.nextInt();
     int product=M*N;
     Double result=0.0;
     for(int i=2;i<product/2;i++)



10 15

9 3





Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor( at at java.util.Scanner.nextInt( at java.util.Scanner.nextInt( at Codechef.main(

My program actually prints the minimum squares that can be made from the given length*breadth dimension my code is working fine when i am taking input once but i want to take as many inputs as the user wants,for this i have applied for loop before taking input M and N but it throws runtime error now although it works fine without that for loop in line:15 any help would be appreciated.thanks in advance


I see that your loop will be infinite, as you haven't increased your counter. And since that is an infinite loop it exhausts your input, which is the reason for that exception.

add k++ in the first loop, like you have i++ in the second loop. That should fix it.

Need Your Help

how to setup sites framework in django

python django django-models django-sites

I am trying to setup multiple sites from a single project in django. I was trying to set this up following but there is no mention of setu...

FindBugs not accepting bcel.jar in ANT script

java ant findbugs task bcel

I installed findbugs into my ant lib directory and added the following code into my main ANT script: