| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/MKhawlah/Java-Programs/master/Basic-Programs/sum_of_digit.java | [Back] [Original] |
import java.util.Scanner;
/**
*
* @author Divyanshu
*/
public class sum_of_digit {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the no. - ");
int n=in.nextInt();
int sum=0,res;
while(n>0){
res=n%10;
sum=sum+res;
n=n/10;
}
System.out.println("Sum of digits: "+sum);
in.close();
}
}
| Web Proxy Viewer | New URL | Original Page |