Picking Values from a range of numbers where tens do not repeat

0

I would like a way to solve a problem consisting of reading 2 user numbers that will be my start and end ex 10 and 50 and within that range do not show the repeated numbers ex 11,22,33,44. p>     

asked by anonymous 12.04.2017 / 15:17

1 answer

0

You could transform this int to String and thus compare your substring or even use a regular expression

Something like this:

int inicio = 0;
int fim = 50;

for (int i = inicio; i < fim; i++) {
  String check = String.valueOf(i);
  if (check.length() > 1) {
    if (check.substring(0, 1).equals(check.substring(1, 2))) {
      System.out.println(i); //mostro os repetidos
    }
  }
}
    
12.04.2017 / 16:13