Wednesday, 18 September 2013

Boolean with loops to check an array

Boolean with loops to check an array

Write Java code for a loop that sets boolean variable isOrdered to true if
the elements of a
given array of ints called a are in non-decreasing order, otherwise it
sets isOrdered to false.
int i[] = { 1, 2, 3, 4, 5 };
int b = 0;
boolean isOrdered = false;
while (b < i.length) {
if (i[0] <= i[b]) {
isOrdered = true;
}
b++;
}
out.println(isOrdered);
Am I doing this correctly?

No comments:

Post a Comment