Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

Quearn

Quearn Logo Quearn Logo

Quearn Navigation

  • Home
  • Quearn Academy (Free Courses)
  • Sili (Free AI)
  • Quearn Drive (30GB Free Storage)
  • Guest Post (Lifetime Dofollow Backlink)
  • About Us
  • Blog
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Quearn Academy (Free Courses)
  • Sili (Free AI)
  • Quearn Drive (30GB Free Storage)
  • Guest Post (Lifetime Dofollow Backlink)
  • About Us
  • Blog
Home/Questions/Q 803890
Next
In Process

Quearn Latest Questions

codemania
  • 0
codemania
Asked: May 27, 20232023-05-27T09:37:25+00:00 2023-05-27T09:37:25+00:00In: Education

Java Program to Check if an Array is Increasing

  • 0
Java Program to Check if an Array is Increasing
codejava
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    1. codemania
      codemania
      2023-05-27T09:38:01+00:00Added an answer on May 27, 2023 at 9:38 am

      This is the Java Program to Check if an Array is Strictly Increasing.

      Problem Description

      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.

      Problem Solution

      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.

      Program/Source Code

      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.

      1. //Java Program to Check if an Array is Strictly Increasing
      2. import java.io.BufferedReader;
      3. import java.io.InputStreamReader;
      4. public class StrictlyIncreasing {
      5.     // Function to check array is strictly increasing or not.
      6.     static boolean checkStrictlyIncreasing(int[] array){
      7.         boolean result=true;
      8.         int i;
      9.         for(i=0;i<array.length-1;i++){
      10.             if(array[i]>=array[i+1])
      11.             {
      12.                 result=false;
      13.                 break;
      14.             }
      15.         }
      16.         return result;
      17.     }
      18.     // Function to read the user input
      19.     public static void main(String[] args) {
      20.         BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
      21.         int size;
      22.         System.out.println("Enter the size of the array");
      23.         try{
      24.             size=Integer.parseInt(br.readLine());
      25.         }
      26.         catch(Exception e)
      27.         {
      28.             System.out.println("Invalid Input");
      29.             return;
      30.         }
      31.         int[] array=new int[size];
      32.         System.out.println("Enter array elements");
      33.         int i;
      34.         for(i=0;i<array.length;i++){
      35.             try{
      36.                 array[i]=Integer.parseInt(br.readLine());
      37.             }
      38.             catch(Exception e)
      39.             {
      40.                 System.out.println("An error occurred");
      41.                 return;
      42.             }
      43.         }
      44.         boolean result=checkStrictlyIncreasing(array);
      45.         if(result){
      46.             System.out.println("Array is strictly increasing");
      47.         }
      48.         else{
      49.             System.out.println("Array is not strictly increasing");
      50.         }
      51.     }
      52. }
      Program Explanation

      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.

      Runtime Test Cases
       
      Case 1 (Positive Test Case):
       
      Enter the size of the array
      5
      Enter array elements
      1
      2
      3
      4
      5
      Array is strictly increasing
       
      Case 2 (Negative Test Case):
       
      Enter the size of the array
      8
      Enter array elements
      1
      2
      2
      3
      4
      5
      6
      6
      Array is not strictly increasing
       
      Case 3 (Positive Test Case - another example):
       
      Enter the size of the array
      7
      Enter array elements
      12
      24
      45
      56
      678
      890
      980
      Array is strictly increasing
      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Related Questions

    • Codility Passing Car Problem in Java
    • Dutch National Flag Problem in Java
    • Java Program to Check if an Array is Decreasing
    • Smallest Sum Contiguous Subarray in Java
    • Java Program to Find the Largest Subarray with Equal Number of 0s and 1s

    Sidebar

    Ask A Question
    • Popular
    • Answers
    • imran

      Point out the wrong statement. A. The standard instances are ...

      • 284 Answers
    • imran

      Point out the correct statement. A. A volume is mounted ...

      • 261 Answers
    • VARISHA PARVEZ

      Which type of e‐commerce focuses on consumers dealing with ...

      • 181 Answers
    • Sourabh Pandey
      Sourabh Pandey added an answer a) true July 21, 2023 at 7:20 am
    • Sourabh Pandey
      Sourabh Pandey added an answer a) dispersion coefficient = magnetizing current / ideal short circuit… July 21, 2023 at 7:20 am
    • riya Dhwan
      riya Dhwan added an answer current July 8, 2023 at 10:48 pm

    Related Questions

    • 28. _____________are NOT a part of the Scheduled banking ...

      • 1 Answer
    • 25. A bank is a financial intermediary because A. it ...

      • 1 Answer
    • 24. How many developments banks are there in India? A. ...

      • 1 Answer
    • 23. Who insures banks in India? A. IRDA B. EXIM ...

      • 1 Answer
    • 22. What is the full-form of NBFC? A. Non-Bank Financial ...

      • 1 Answer

    Top Members

    Misba Waqas

    Misba Waqas

    • 0 Questions
    • 0 Answers
    R.R.R SPORTS

    R.R.R SPORTS

    • 0 Questions
    • 0 Answers
    Farhan Butt

    Farhan Butt

    • 0 Questions
    • 0 Answers

    Trending Tags

    account algorithm analytics answer c computer computer science python cs e commerce electric electronics it language mcq mechanical physics poll programming python question

    Explore

    • Quearn Do QnA Earn Money
    • Quearn Academy
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help

    Footer

    Quearn

    Quearn is a social questions & Answers Engine which will help you establish your community and connect with other people, Also you Can Earn Money.

    About Us

    • Meet The Team
    • Blog
    • About Us
    • Contact Us

    Legal Stuff

    • Terms of Use
    • Privacy Policy
    • Cookie Policy

    Help

    • Knowledge Base
    • Support

    Follow

    © 2018-2023 Quearn®. All Rights Reserved | Developed by ASHAS Industries Proudly 🇮🇳

    Enable Notifications OK No thanks