Guest User

Untitled

a guest
Oct 15th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. void firstline() {
  2. Scanner in = new Scanner(System.in);
  3. out.printf("");
  4. String Line = in.nextLine();
  5. Scanner line = new Scanner(Line);
  6.  
  7. int somcijfers = 0;
  8. while(line.hasNext()) {
  9. somcijfers += line.nextInt();
  10. }
  11. out.printf("%d", somcijfers);
  12.  
  13. }
  14.  
  15. void start() {
  16. firstline();
  17. }
  18.  
  19. String s = "Piet van Gogh_5 6 7 4 5 6";
  20. String vals = s.substring(s.lastIndexOf('_') + 1);
  21. String[] nums = vals.split(" ");
  22.  
  23. try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
  24. String line = br.readLine();
  25. String[] splitLine = line.split("_");
  26. String[] numbers = splitLine[1].split(" ");
  27. Integer sum = Stream.of(numbers).mapToInt(Integer::valueOf).sum();
  28. System.out.println(sum);
  29. } catch (IOException e) {
  30. e.printStackTrace();
  31. }
Add Comment
Please, Sign In to add comment