Created
December 7, 2013 03:31
-
-
Save Fogest/7836948 to your computer and use it in GitHub Desktop.
Find a unique year
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test1; | |
import java.util.Scanner; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class Question1 | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner input = new Scanner(System.in); | |
Boolean checker = false; | |
String regex = "^(?:([0-9])(?!.*\1))*$"; | |
Pattern pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE); | |
System.out.println("Enter the Year:"); | |
String number = input.next(); | |
int year = Integer.valueOf(number); | |
Matcher matcher; | |
while(!checker) { | |
matcher = pattern.matcher(number); | |
if(matcher.find()) | |
checker = true; | |
else | |
year++; | |
number = Integer.toString(year); | |
} | |
System.out.println(number); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment