I have a array:
int tarningar[] = new int[5];
That holds numbers. When all the numbers are the same, system.out.println('ok');
How can I do this?
Here's a more succinct Java 8 streams example:
Arrays.stream(tarningar).distinct().count() == 1
boolean flag = true;
int first = tarningar[0];
for(int i = 1; i < 5 && flag; i++)
{
if (tarningar[i] != first) flag = false;
}
if (flag) System.out.println("ok");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With