Â
In this, we are going to write a simple program to check whether the inputted numbers are ascending order or not in Java.
import java.util.*;
class demo
{
public static void main(String[] args)
{
int i, n, f = 0, p = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter 5 integers:");
for (i = 1; i <= 5; i++)
{
n = sc.nextInt();
if (i == 1)
{
p = n;
}
else
{
if (n < p)
{
f = 1;
}
p = n;
}
}
if (f == 0)
{
System.out.println("The numbers are in ascending order");
}
else
{
System.out.println("The numbers are not in ascending order");
}
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP