Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Parseint {
- public static int parseInt(String str) {
- if (str == null || str.isEmpty()) {
- System.out.println("Der String enthaelt keine Zeichen");
- return -1;
- } else {
- int sum = 0;
- int position = 1;
- for (int i = str.length() - 1; i >= 0; i--) {
- int number = str.charAt(i) - '0';
- sum += number * position;
- position = position * 10;
- }
- return sum;
- }
- }
- public static void main(String[] args) {
- int a = parseInt("");
- System.out.println(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement