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.
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…