I wanted to know if anyone could help me deal with this problem. The purpose of the program is that the user enters the year, say, 1980, and the program returns next year with distinctive numbers, the distinctive numbers are all different, for example, 2013-2019, 2012 is not distinctive, since number two occurs twice, 2013 -2019 years are different, because the numbers are found only once.
User enters a year. The program calculates the next year, which has distinctive numbers
This is the code that I have right now. Its sole purpose right now is to return true, if the number the user enters is different, I could find a way to do this using the String and charAt type. I don’t think you can increase the strings, but if the user can enter int, and the program continues to increase until it finds a number that is different, but all I can think of is a function that takes a string. Is there a similar method that I could do using int as a parameter, or is there a way I could make it work with strings?
public static boolean hasDuplicates(String text){
for(int i = 0; i < text.length() - 1; i++){
for(int j = i + 1; j < text.length(); j ++){
if(text.charAt(i) == text.charAt(j)){
return true;
}
}
}
return false;
}
Any advice is appreciated. Also my apologies for the lack of tags. Edit: Thank you. Full code at http://pastebin.com/FQj1yeCk
source
share