if num=687;
U have to get
num=6+8+7;

Answer Posted / asit

public class addDigit {
public static void main(String args[])
{
int num=56782;
int sum=0;
while(num!=0)
{
sum=sum+num%10;
num=num/10;
}
System.out.print(sum);
}

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is use of a abstract variable?

543


When can we say that threads are not lightweight process in java?

596


Explain the difference between string, stringbuffer and stringbuilder in java?

565


What is the output of the below java program?

596


Which is easier netbeans or eclipse?

614






Can we initialize the final blank variable?

588


What is the gregoriancalendar class in java programming?

574


What is parsing a string?

592


Can we convert stringbuffer to string?

566


How to display all the prime numbers between 1 and n (n is the number, get the input from user)

516


Difference between final and effectively final ?

640


What is meant by 'Class access modifiers'?

557


Define immutable object?

584


How do you check if a character in a string is a digit or letter?

513


Is null function in java?

570