Created
June 22, 2022 21:59
-
-
Save racecraftr/957114edb10d276ccfd3d33bd6d4560c to your computer and use it in GitHub Desktop.
Day 16 of the Useless Java series.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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