Java programming code
Thursday, January 15, 2009
/* This program calculate the summation of the digit of a given number Sample Input 123456789 Sample output 45 */ import java.io.*; class sum_digit { public static void main(String args[])throws IOException { long sum=0; System.out.print("Enter your number:"); BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); String a=ob.readLine(); long m=Long.parseLong(a); while(m!=0) { long n=m%10; sum=sum+n; m=m/10; } System.out.println("The sum of the digit of the number:"+sum); } }
0 comments:
Post a Comment