Math, asked by anshitasitesh, 8 months ago

write a program in java to input four digit number and arrange in ascending order​

Answers

Answered by aadarrshofficial
1
I know java but now I am using my mobile sorry...
Answered by ksai343434
0

This is the steps to build your structure for program and steps.

Import the necessary classes then,

Begin class body and main method.

Instantiate Scanner object so it can read the input,

Instantiate and initialize variable to store the input number/[s]

Read input. Check if it has three digits or more. If it has, then proceed to next step. or else, repeat this step.  

*Refer How to read integer value from the standard input in Java & Asking user to enter the input again after he gives a wrong value for the Input. InputMismatchException?

(Note: you need to  understand how many digits long your input can be and then choose the datatype Integer/Long accordingly - this answer assumes input will fit within the size of an Integer.)

Instantiate a list to store digits of input number.

Revisit Step 1, if it is needed.

Extract the digits from the number and insert into the list.

*Refer How to get the separate digits of an int number?

As we need the sorted output, order of extraction of digits is not a concern. Proceed to sort the list. Refer How to sort an ArrayList? Revisit Step 1, if needed.

Display the output in the desired format from the List.

Cleanup resources - viz., close the Scanner object created in step 3.

End main method and class body.

Similar questions