Guest User

Untitled

a guest
Feb 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. public class TryoutCijferSom {
  2. public static void main (String []arg) {
  3.  
  4. System.out.print("Geef een getal: ");
  5. int getal = Console.readInt();
  6. int som = getCijferSom(getal);
  7. if (getal <0) {
  8. System.out.println( "De som van de cijfers is -" + som);
  9. }
  10. else {
  11. System.out.println("De som van de cijfers is " + som);
  12. }
  13.  
  14. }
  15. private static int getCijferSom(int i) {
  16.  
  17. int ant = 0;
  18. i = Math.abs(i);
  19.  
  20. while (i > 0) {
  21. ant = ant + i % 10;
  22. i /= 10;
  23. }
  24. return ant;
  25. }
  26. }
Add Comment
Please, Sign In to add comment