/* 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(System.in);
int testcase;
testcase = sc.nextInt();
while(testcase--)
{
int n , i , sum = 0 ;
n = sc.nextInt();
while( n != 0)
{
sum = sum + (n % 10);
n = n/10;
}
System.out.println(sum);
}
}
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++.
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