Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. /**
  6. * Zad 1. Wypisanie kod�w pocztowych i miast w formacie xx xxx Miasto, z formatu
  7. * xx-xxx Miasto. Miasto rozpoczyna si� wielk� liter�, reszta ma�a
  8. *
  9. * Zad 2. Wykoanie sumy dochod�w
  10. *
  11. * Zad 3. Wykonanie sumy podanych liczb
  12. * @author Damian
  13. *
  14. */
  15. public class Log {
  16.  
  17. // wypisanie samych danych o dochodach
  18. // wypisanie kodow pocztowych w formacie xx xxx, z xx-xxx np.10-100 na 10
  19. // 100
  20. // konwersja liczb zapisywanych w pliku do formatu zmiennoprzecinkowego, np.
  21. // 10
  22. // 10 = 10.10
  23. public static void main(String[] args) {
  24. Scanner scanner = new Scanner(System.in);
  25. System.out.println("Prosze o podanie hasla");
  26. String haslo = scanner.nextLine();
  27.  
  28. test1(haslo);
  29. if(test1(haslo) == true) {
  30. System.out.println("Podane haslo jest poprawne");
  31. }
  32. else {
  33. System.out.println("Podane haslo jest niepoprawne");
  34. }
  35.  
  36.  
  37. }
  38. private static boolean test1(String a) {
  39. String pattern = "^[0-9]{2}[a-zA-Z.]{2}\\s[a-zA-Z.]{3,}[0-9]{2}$";
  40. Pattern r = Pattern.compile(pattern);
  41. Matcher m = r.matcher(a);
  42. boolean test= m.matches() ;
  43. if( test == true) return true;
  44. else return false;
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement