SHARE
TWEET

Untitled

a guest Apr 21st, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static int quersumme3(int zahl) {
  2.         String zahlAlsString = String.valueOf(zahl);
  3.         int laengeString = zahlAlsString.length();
  4.         int qs3 = 0;
  5.         for (int i = 0; i < laengeString; i++) {
  6.             // Variante 1 mit substring
  7.             //System.out.println(zahlAlsString.substring(i, i+1));
  8.             //qs2 = qs2 + Integer.parseInt(zahlAlsString.substring(i, i+1));
  9.            
  10.             // Variante 2 über charAt (etwas umständlicher da öfters Casting notwendig)
  11.             //System.out.println(Integer.parseInt(String.valueOf(zahlAlsString.charAt(i))));
  12.             qs3 = qs3 + Integer.parseInt(String.valueOf(zahlAlsString.charAt(i)));
  13.         }
  14.         return qs3;
  15.     }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top