java execution problem in running issue

this following code doesn"t run say ki testcase cannot be converted to int from string…i m declaring testcase as integer only…please help me in this.

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.

/* Name of the class has to be “Main” only if the class is public. */

class Codechef

public static void main (String[] args) throws java.lang.Exception
	Scanner sc = new Scanner(;
	int testcase;
	testcase = sc.nextInt();
	    int n , i , sum = 0 ;
	    n = sc.nextInt();
	    while( n != 0)
	        sum = sum + (n % 10);
	        n = n/10; 


There are a few problems in the code that you have provided.

(1.) You have not written anything after the ‘.’ in


They should be


(2.) In Java, while() requires a boolean value but you have written testcase-- which is an integer value. So change it to

while(testcase-- > 0)

After these changes, your code should work fine.

the diffirence b/w testcase-- and testcase–>0
is testcase-- works fine c++ but in java all loops take boolean value only so that testcase-- doesnot work on java
testcase–>0 gives a boolean vale

java.util.* is mentioned in code…here i forgot to write…but what is the difference in testcase-- and testcase-- > 0 …both are same right??how are they different??

As I said while() requires a boolean value, but testcase-- is not a boolean value, its an integer value. By writing it like testcase-- > 0, we have used the relational operator ‘>’ (greater than) and made it a boolean value. This is the difference. Java is different in this case from C/C++.