How would you go about skipping non-numeric characters in a string and only adding the sum of the numbers a multi line string?

I think I've made some progress. I can at least know which index values in my string are numbers. But I'm not sure how to actually get those values. I'm getting 199 for the sum, I'm really not sure where that is coming from since my indexes that are numbers are only 4,10,16 and 20.

String test = "Word1 Word2 Word3\nW 1";
          Scanner scan = new Scanner(test);
          int sum = 0;
            for(int i = 0;i<test.length();i++){
                if(Character.isDigit(test.charAt(i))){
                    System.out.println(i);
                    sum += test.charAt(i);
                }
            }
            System.out.println("sum = "+sum);

Nevermind. I got it. I guess I wasn't quite on the right track.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.