Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Punto_1 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Escriba un numero");
- long n = sc.nextLong();
- int resultado = sumarDigitos(n);
- System.out.println( resultado);
- sc.close();
- }
- public static int sumarDigitos(long n) {
- long np = n;
- int s = 0;
- while (np != 0) {
- s = (int) ((np % 10) + s);
- np = np / 10;
- }
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement