Skip to content

Instantly share code, notes, and snippets.

@Fogest
Created December 7, 2013 03:31
Show Gist options
  • Save Fogest/7836948 to your computer and use it in GitHub Desktop.
Save Fogest/7836948 to your computer and use it in GitHub Desktop.
Find a unique year
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