Computer Science, asked by kundunilay89, 5 months ago

Write a program to pass an integer as argument and check whether the digits are in ascending
order or not

Answers

Answered by aadishree1601
1

Answer:

Simple Iterative Solution

The integer entered by the user is stored in variable n. Then the while loop is iterated until the test expression n != 0 is evaluated to 0 (false).

After first iteration, the value of n will be 345 and the count is incremented to 1.

After second iteration, the value of n will be 34 and the count is incremented to 2.

After third iteration, the value of n will be 3 and the count is incremented to 3.

At the start of fourth iteration, the value of n will be 0 and the loop is terminated.

Explanation:

pls mark me as branlist

Answered by duragpalsingh
0

Question:

Write a program to input an integer and check whether al digits are in ascending order or not.

Solution:

Language used: Java

import java.util.*;

public class Question45

{

static void main()

{

Scanner sc=new Scanner(System.in);

int d1,d2,n,f=0;

System.out.println("Enter an integer:");

n=sc.nextInt();

while(n>9)

{

d2=n%10;

d1=(n/10)%10;

if(d1>d2)

f=1;

n=n/10;

}

if(f==0)

System.out.println("All digits are in ascending order");

else

System.out.println("All digits are not in ascending order");

}

}

Similar questions