How to find some of digits of any given number
import java.util.*;
class A
{
int a,n,b,z,c=0;
void get()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter any number ");
n=sc.nextInt();
z=n;
}
void put()
{
while(n!=0)
{
a=n%10;
b=n/10;
n=b;
c=c+a;
}
System.out.print("number is "+z+"sum of all digits is "+c);
}
public static void main(String[] args)
{
A a=new A();
a.get();
a.put();
}}
import java.util.*;
class A
{
int a,n,b,z,c=0;
void get()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter any number ");
n=sc.nextInt();
z=n;
}
void put()
{
while(n!=0)
{
a=n%10;
b=n/10;
n=b;
c=c+a;
}
System.out.print("number is "+z+"sum of all digits is "+c);
}
public static void main(String[] args)
{
A a=new A();
a.get();
a.put();
}}
No comments:
Post a Comment