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

Scanner scan = new Scanner(System.in);
int in = scan.nextInt();

String s = in + "";

int sum = 0;
int div = 10;
int di = 1;

for (int i = 0; i < s.length(); i++) {
int rem = in % div;
rem = rem / di;
sum += rem;
div *= 10;
di *= 10;

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

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is j2ee specification?

889


What is pure java?

1001


I’m new to WebLogic Does anyone knows how to Deploy Application using

2174


How do I become a java developer?

932


What are struts?

891


What is java transaction api (jta)?

924


What is j2ee product provider?

918


What is document root?

909


What is event handling in java?

872


public class ActionDTO extends GenericDTO implements Serializable,Auditable { // default serial version id, required for serializable classes. public static final String ACTION_SUSPEND = "SPN"; public static final String ACTION_DEREGISTER = "DRR"; public static final String ACTION_REINSTATE = "REI"; private static final long serialVersionUID = 1L; private Long actionId; private long accountId; private Date actionDate; private String actionType; private String remarks; private AccountDTO account; public ActionDTO() { } public ActionDTO(Long accountId, String action, String remarks, String updatedBy) { setAccountId(accountId); setActionType(action); setActionDate(new Date()); setRemarks(remarks); setUpdatedBy(updatedBy); } public Long getActionId() { return this.actionId; } public void setActionId(Long actionId) { this.actionId = actionId; } public long getAccountId() { return this.accountId; } public void setAccountId(long accountId) { this.accountId = accountId; } public Date getActionDate() { return this.actionDate; } public void setActionDate(Date actionDate) { this.actionDate = actionDate; } public String getActionType() { return this.actionType; } public void setActionType(String actionType) { this.actionType = actionType; } public String getRemarks() { return this.remarks; } public void setRemarks(String remarks) { this.remarks = remarks; } // bi-directional many-to-one association to AccountDTO public AccountDTO getAccount() { return this.account; } public void setAccount(AccountDTO account) { this.account = account; } @Override public String toString() { // TODO Auto-generated method stub return null; } } what is the purpose of @Override public String toString()...and what will do here ?

2574


What is difference between java and core?

931


What is considered as a web component?

1051


What is j2ee module?

985


How do I run java?

864


What is tomcat in j2ee?

862