Categories: softare development

Write a static method that takes int number as input argument and returns the sum of the digits of that number.


public CheckSum {


public static void main (String []args){

System.out.println(digitSum(45));

public static int digitSum(int number) {
  
 int sum = 0;
         
        while (number != 0)
        {
            sum = sum + number % 10;
            number = number/10;
        }
     
    return sum;
 }
}
}

Check if a given number is perfect square in Java

Recent Posts

JavaScript vs Your Expectations

Almost everyone starts learning JavaScript with the wrong expectations. Let's fix them. Download the Codeflare…

2 days ago

Introduction to Phaser JS

Phaser JS is a powerful, open-source HTML5 game development framework used for creating 2D games that…

7 days ago

Web Authentication Libraries

JavaScript / Node.js Authentication Libraries 1. Passport.js One of the most popular authentication middleware libraries…

7 days ago

The Things They Carry: Software Developers Starter Packs

Every profession comes with its own set of tools. A carpenter has a toolbox, a…

7 days ago

CRUD Operations: The Foundation of Data Management

Every application that stores and manages data relies on a set of basic operations known…

3 weeks ago

Common PHP Mistakes Every Developer Should Avoid

PHP remains one of the most widely used server-side programming languages, powering platforms such as…

3 weeks ago