Advertisement
petar088

Rage Quit

May 7th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. package Fundamentals._28_Text_Regex_Exercise.More_Exercise;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class _7_Rage_Quit {
  8. public static void main(String[] args) {
  9. Scanner sc = new Scanner(System.in);
  10.  
  11. String input = sc.nextLine();
  12. String regex = "[^\\d]*(?<number>[\\d]*)[^\\d]*";
  13.  
  14. Pattern pattern = Pattern.compile(regex);
  15. Matcher matcher = pattern.matcher(input);
  16.  
  17. while (matcher.find()){
  18.  
  19. int num = Integer.parseInt(matcher.group("number"));
  20. String foIndex = String.valueOf(num);
  21. System.out.println(num);
  22. int index = input.indexOf(foIndex);
  23. System.out.println(index);
  24.  
  25.  
  26. }
  27.  
  28.  
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement