java coding to find sum of digits eg..if n= 123..... ans is 6 ...
Answers
Answered by
2
[0010001111]... Hello User... [1001010101]
Here's your answer...
Its been a long time since I've written a Java program.
import java.util.*;
class Sum
{
public static void main[]
{
Scanner in=new Scanner(System.in);
int n,s=0;
System.out.println("Enter the number");
n=in.nextInt();
while(n>0)
{
int a=n%10;
s+=a;
n/=10;
}
System.out.println(s) ;
}
}
[0110100101]... More questions detected... [010110011110]
//Bot UnknownDude is moving on to more queries
//This is your friendly neighbourhood UnknownDude
Here's your answer...
Its been a long time since I've written a Java program.
import java.util.*;
class Sum
{
public static void main[]
{
Scanner in=new Scanner(System.in);
int n,s=0;
System.out.println("Enter the number");
n=in.nextInt();
while(n>0)
{
int a=n%10;
s+=a;
n/=10;
}
System.out.println(s) ;
}
}
[0110100101]... More questions detected... [010110011110]
//Bot UnknownDude is moving on to more queries
//This is your friendly neighbourhood UnknownDude
riyashukla74:
thanks
Similar questions