Java program to print next greater elements in a given array

By: Editorial Staff | Last Updated: | In: Java Programming


In this program, we are going to share a Java program to print next greater elements in a given array. If you are a Java beginner and want to start learning the Java programming, then keep your close attention in this tutorial as I am going to share how to write a Java program to print next greater elements in a given array.

To increase your Java knowledge, practice all Java programs, here is a Collection of 100+ Java problems with solutions.

Java program to print next greater elements in a given array with the output

Copy the below Java program and execute it with the help of Javac compiler. At the end of this program, We have shared the output of this program.

class Main
{
static void printNGE(int arr[], int n)
{
int next, i, j;
for (i=0; iOutput:

11 — 13
13 — 21
21 — -1
3 — -1

Same programs in other languages:

C# program to print next greater elements in a given array

Share this post!


About: Editorial Staff

Editorial Staff at FreeWebMentor is a team of professional developers leads by Prem Tiwari