+ 2
can anyone explain me result line??
import java.util.stream.IntStream; public class Palindrome { public static void main(String[] args) { String num = "1234321"; int pos = num.length()-1; int middle = num.length()/2; int result = IntStream.rangeClosed(0, middle).anyMatch(i -> num.charAt(i) != num.charAt(pos - i)) ? 0 : 1; System.out.println(result!=1?"false":"true"); } }
1 Resposta
+ 1
result = IntStream // generate numbers
.rangeClosed(0, middle) // 0,1,2,3
.anyMatch( i -> // as i; if any
num.charAt(i) != // char from begin is not equals to
num.charAt( pos-i) // char from the end
// break and get true (else false);
) ? "false" : "true"; // if got true (=not equals)
// result = "false" else "true"