Array programs in Java

Question

This is the most frequently asked array programs in java. Write a program to find whether the next element is bigger than the current element in an array.

Greater than previous

Logic

  • The logic is very simple, compare the next element with the current element.
  • If it is bigger then print the number.
  • Increment the index count and repeat the same process till we reach the (n-1) index position.

Program

class Matches
{
   public static void main(String ar[])
   {
     int array[] ={ 2,-3,-4,5,9,7,8};
     int len= array.length;
     for(int i=0;i<len-1;i++)
     {
         if(array[i+1]>array[i])
                   System.out.println(array[i+1]);
         
     }
   }
}

You might also like…

Check for a pair in array which is equal to sum | Infosys

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Sree Hari Sanjeev

The founder of Wisdom Overflow. Software Developer at Zoho Corporation.
0 0 votes
Article Rating
Subscribe
Notify of
guest
5.4K Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
5.4K
0
Would love your thoughts, please comment.x
()
x