Home » Sometech » WAP in JAVA to implement the sum of the digits of a number.

WAP in JAVA to implement the sum of the digits of a number.

Java Coding

import java.util.Scanner;

class sumofdigit

{

public static void main(String arg[])

{

int n,s=0;

Scanner ss=new Scanner(System.in);

System.out.println(“Enter the number”);

n=ss.nextInt();

while(n>0)

{

s=s+n%10;

n=n/10;

}

System.out.println(“The sum of digit is = “+s);

}

}

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: