AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

# programming-basics: Sorting Numbers from smallest to largest

 Program to take the input from the user and print the same numbers in sorted order from smallest to largest. The user will input a zero to mark the end of the input. Assume that at most 100 positive numbers will be entered. programming x 168basics x 171 Posted On : 2017-10-20 13:20:27.0 Anonymous User 1300 3

## Answers

 import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class SortingNumber { public static void main(String[] args) { Scanner input=new Scanner(System.in); int inputNumber; Set numberSet=new TreeSet(); while((inputNumber=input.nextInt())!=0){ numberSet.add(inputNumber); } System.out.println(numberSet); } } Posted On : 2017-10-20 17:04:53 Satisfied : 0 Yes  0 No Garima Gupta 596129026817Reply This Thread 0
Comments
Please give a solution without using Set
Anonymous User
13  0  0
Posted On :2017-10-23 23:01:07.0
Leave a Comment
There can be lot of ways of this problem. Please elaborate more what exactly you are looking for. Also it´ll be better if you can give some input and output data. Please check below code.

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class SortingNumber {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int inputNumber;
List<Integer> numbers=new ArrayList<Integer>();
while((inputNumber=input.nextInt())!=0){
numbers.add(inputNumber);
}
Collections.sort(numbers);
System.out.println(numbers);
}
}

Note:
-----------------
Use Leave a Comment or Reply a thread option to discuss about the posted answer. Don´t post your comments as answer.
Garima Gupta
596  1290  26817
Posted On :2017-10-23 23:06:45.0
Leave a Comment
this program also showing output like this:
[14, 24, 29, 34, 44, 48, 56, 65, 67, 89]
please provide a solution for a list without braces and comas
Anonymous User
13  0  0
Posted On :2017-10-25 11:18:47.0
Leave a Comment
Write a program to take the input from the user and print the same numbers in sorted order from smallest to largest. The user will input a zero to mark the end of the input. Assume that at most 100 positive numbers will be entered.

Sample Input:

56

48

89

14

29

65

34

67

2

4

44

0

Sample output:

2

4

14

29

34

44

48

56

65

67

89

please give a solution for this..thank you sir
Anonymous User
13  0  0
Posted On :2017-10-25 11:21:29.0
Leave a Comment
Hi,
If you want the output in above specified format just iterate the List or Set and print the elements one by one instead of printing complete list together. Please check below code:

for(int i=0;i<numbers.size();i++){
System.out.println(numbers.get(i));
}

If you don´t want to use Set or sort method of collection, Please check below link to sort the numbers explicitly:

Sorting Numbers using the given conditions -Click Here

Garima Gupta
596  1290  26817
Posted On :2017-10-25 23:14:27.0
Leave a Comment
it worked successfully...thank you very much sir
Anonymous User
13  0  0
Posted On :2017-10-28 11:40:07.0
Leave a Comment

Post Answer
Please Login First to Post Answer: Login

 Answer: