import java.util.Scanner;
public class GentYears
{ //creating method
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
int startingYear = input.nextInt();
startingYear++;
while(isDistinct(startingYear) == false)
{
startingYear++;
}
System.out.println(startingYear); //output specific element
}
public static boolean isDistinct(int year)
{
boolean isDistinct = true;
int [] digits = new int[10]; // array decleration
while(!(year == 0))
{
digits[year % 10]++;
year /= 10;
}
for(int i = 0; i < digits.length; i++) //populate array with a loop
{
if(digits[i] > 1)
{
isDistinct = false;
i = digits.length;
}
}
return isDistinct;
}
}
Pretty much what my code is doing is it is typing in a year and the program will output the next year with distinct digits. I am trying to error check my program so for any value above 10000 and any value below 1 will cause the program to say "invalid input" and end the program. Feel free to re-arrange my code if you see a way to make it better. Also, is there a way to easily implement a class into this program? I'm not too familiar with classes so I kinda need help with it.