Java Program to Check if an Array is Increasing
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is the Java Program to Check if an Array is Strictly Increasing.
Given an array of integers check whether it is strictly increasing or not.
A strictly increasing array is an array whose each element is greater than it’s preceding element.
Example:
Array = [1, 2, 3, 4, 5]
Output: Array is strictly increasing.
Iterate through the array and check whether the current array element is greater than its preceding element. If all the elements are greater than its preceding element return true, else return false.
Here is the source code of the Java Program to Check if an Array is Strictly Increasing. The program is successfully compiled and tested using IDE IntelliJ Idea in Windows 7. The program output is also shown below.
//Java Program to Check if an Array is Strictly Increasing
// Function to check array is strictly increasing or not.
{
}
}
}
// Function to read the user input
}
{
}
}
{
}
}
}
}
}
}
1. In function checkStrictlyIncreasing(), the loop for(i=0; i<array.length-1; i++) checks whether each array element is greater than the element following it, through the condition if(array[i] >= array[i+1]).
2. Any element that fulfils this condition, implies that the array is not strictly increasing, and it sets the result to false and breaks from the loop.
3. Finally, the boolean variable result is returned as the answer.
Time Complexity: O(n) where n is the number of elements in the array.