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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / sai

int num=687;
int sum=0;

int i;

System.out.println(num);
for(i=num;(sum>=0)&&(i>0);){
//System.out.println(i);
i=num%10;
System.out.println(i);
sum+=i;
//System.out.println(sum);
num/=10;
//System.out.println(i);
}
System.out.println(sum);

Is This Answer Correct ?    10 Yes 7 No

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

Answer / asit purohit

int num=5672;
int sum=0;
while(num%10!=0)
{
sum=sum+num%10;
num=num/10;
}
System.out.println("sum="+sum);

Is This Answer Correct ?    0 Yes 0 No

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

Answer / 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

More Core Java Interview Questions

how to print output with out using sop statements

5 Answers   UHG,


What are the pillars of java?

0 Answers  


What is tostring () method?

0 Answers  


Why are pointers not secure?

0 Answers  


why Java does not support multiple inheritances?

0 Answers   Aspire,






How does multithreading take place on a computer with a single cpu in java programming?

0 Answers  


Can we have multiple classes in single file ?

0 Answers  


Hi Friends, I am beginner in java. what i know about synchonized keyword is,If more that one 1 thread tries to access a particular resource we can lock the method using synchronized keyword. Then after that how the lock is released and how next thread access that.Please explain with example.

5 Answers  


Why Do I Get A "permission Denied" Error After Downloading The .jnlp Java Launcher For The Vkvm?

0 Answers   Cisco,


what is object slice?

0 Answers  


which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?

6 Answers   HP, SparkTG,


What is an argument java?

0 Answers  


Categories