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

Answer Posted / sadikhasan palsaniya

int no=687;
int sum=0;
int temp;

while(no>0)
{
temp = no % 10;
sum += temp;
no = no/10;
}
System.out.println(sum);

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are parsing rules?

498


What is a method declaration?

509


Can we override data members in java?

619


What is the use of conditional statement?

562


when should you use stringbuilder class in a program?

522






Is there a way to increase the size of an array after its declaration?

599


Write a program to print the pattern given below

493


What is the difference between an inner class and a sub-class?

503


What is java life cycle?

533


Why java is not 100% object-oriented?

826


What is a classloader in java?

534


What is the purpose of file class?

541


What is diamond operator in java?

495


Difference between static synchronization vs. Instance synchronization?

557


Explain the private protected method modifier?

542