waltermilner

Untitled

Sep 24th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. public class Test {
  2.  
  3.   static boolean check(String str) {
  4.     int pos = 0;
  5.     while (true) {
  6.       if (pos == str.length()) {
  7.         return false;
  8.       }
  9.       char c = str.charAt(pos);
  10.       if (c == '0') {
  11.         pos++;
  12.         continue;
  13.       }
  14.       return (c == '4');
  15.     }
  16.   }
  17.  
  18.   public static void main(String[] args) {
  19.  
  20.     System.out.println(check("123456")); //false
  21.     System.out.println(check("423456")); //true
  22.     System.out.println(check("0043456"));//true
  23.     System.out.println(check("123456"));//false
  24.     System.out.println(check("0123456"));//false
  25.     System.out.println(check("4"));//true
  26.     System.out.println(check("0"));//false
  27.     System.out.println(check(""));//false
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment