Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class Parseint {
  2. public static int parseInt(String str) {
  3. if (str == null || str.isEmpty()) {
  4. System.out.println("Der String enthaelt keine Zeichen");
  5. return -1;
  6. } else {
  7. int sum = 0;
  8. int position = 1;
  9. for (int i = str.length() - 1; i >= 0; i--) {
  10. int number = str.charAt(i) - '0';
  11. sum += number * position;
  12. position = position * 10;
  13.  
  14. }
  15. return sum;
  16. }
  17. }
  18.  
  19. public static void main(String[] args) {
  20. int a = parseInt("");
  21. System.out.println(a);
  22.  
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement