Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- static boolean check(String str) {
- int pos = 0;
- while (true) {
- if (pos == str.length()) {
- return false;
- }
- char c = str.charAt(pos);
- if (c == '0') {
- pos++;
- continue;
- }
- return (c == '4');
- }
- }
- public static void main(String[] args) {
- System.out.println(check("123456")); //false
- System.out.println(check("423456")); //true
- System.out.println(check("0043456"));//true
- System.out.println(check("123456"));//false
- System.out.println(check("0123456"));//false
- System.out.println(check("4"));//true
- System.out.println(check("0"));//false
- System.out.println(check(""));//false
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment