Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write a program for Sum of the digits for a given number
Ex: suppose user entered Number is 1214,
It should calculate the above number like 1+2+1+4 = 8

Answer Posted / vishal

public void getDigitSum(int num){
int remainder=0;
int sum=0;
String strResult="";
int counter=0;
while(num>0){
remainder=num%10;
sum=sum+remainder;
counter++;
if(counter==1){
strResult=String.valueOf(remainder);
}
else{
strResult=String.valueOf(remainder)+"+"+strResult;
}
num=num/10;


}
System.out.println(strResult+"="+sum);
}

Is This Answer Correct ?    11 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is java is a technology?

911


What is server in j2ee?

813


How do you make a class immutable in java?

800


What is java servlet container?

889


Describe the ear, war, and jar.

862


How do you run a java program?

873


What does java ee stand for?

822


What is java ee used for?

783


What is the use of method save()?

904


What is basic authentication?

936


What is javamail?

880


What does j2ee stand for?

838


What is ejb module?

884


What does the application client module contain?

873


How do I become an expert in java?

890