Skip to content

Instantly share code, notes, and snippets.

@racecraftr
Created June 22, 2022 21:59
Show Gist options
  • Save racecraftr/957114edb10d276ccfd3d33bd6d4560c to your computer and use it in GitHub Desktop.
Save racecraftr/957114edb10d276ccfd3d33bd6d4560c to your computer and use it in GitHub Desktop.
Day 16 of the Useless Java series.
package UselessJava.Day16;
import java.util.Scanner;
public class Day16 {
public long sumOfString(String s){
long sum = 0;
String[] strings = s.split("\\D");
for(String string : strings) {
if(string.length() > 0) {
long n = Long.parseLong(string);
sum += n;
}
}
return sum;
}
}
class Main{
public static void main(String[] args) {
Day16 d = new Day16();
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("Enter a string");
String s = sc.nextLine();
System.out.println(d.sumOfString(s));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment