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

[code lang=”java”]
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]);

}
}
}
[/code]

You might also like…

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

Sree Hari Sanjeev

The founder of Wisdom Overflow. Software Developer at Zoho Corporation.

Leave a Reply

Your email address will not be published. Required fields are marked *