Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) throws Exception {
  4. Scanner sc = new Scanner(System.in);
  5. System.out.println("Podaj PESEL");
  6. String pesel = sc.next();
  7.  
  8. if(String.valueOf(pesel).length() != 11) {
  9. throw new Exception("PESEL musi zawierac 11 liczb");
  10. }
  11. if(!containsDigits(pesel)){
  12.  
  13. throw new Exception("Podano litere zamiast cyfry");
  14. }
  15.  
  16.  
  17. }
  18.  
  19. public static boolean containsDigits(String pesel) {
  20.  
  21. char[] peselAr = pesel.toCharArray();
  22. for(int i=0; i<peselAr.length;i++)
  23. if((int)peselAr[i] < 48 || (int)peselAr[i] > 57) return false;
  24. return true;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement