answersLogoWhite

0

How do you sort two digits in java?

User Avatar

Anonymous

13y ago
Updated: 8/20/2019

If all you're dealing with is two digits, there are multiple ways of sorting them.

1. It can be done manually with a simple if comparison:

if (a < b) {

// a is smaller

} else if (a > b) {

// a is larger

} else {

// a equals b

}

2. You can use the Math class:

Math.max(a, b); // returns the larger of the two numbers

Math.min(a, b); // returns the smaller of the two numbers

3. If added to a Collection, you can sort it. (This will work for any number of items added to the Collection, and uses the natural ordering of the items).

ArrayList numberList = new ArrayList();

numberList.add(a);

numberList.add(b);

numberList = Collections.sort(numberList);

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What bank has this sort code 00-39-16?

This is an invalid sort code. It does not exist. No sort code begins with "00". The minimum the first two digits can be is "01".


What sort of plays are popular in Java and Bali?

Snuff films are quite popular in Java and Bali


What is the pseudo code of radix sort in java?

:-P


What bank has sort code 54-3-64?

This sort code is invalid. A sort code must have exactly six digits. The one provided above only has five digits.


What bank sort code is 25-35-49?

This sort code does not exist. The first two digits, "25", mean that the bank in question is Barclay's Bank. However the branch section of the sort code are invalid.


What is Halifax sort code?

A Halifax sort code is a six-digit number used to identify specific branches of Halifax Bank in the UK for the purpose of processing transactions. The format is typically two digits, a hyphen, followed by another two digits, and ending with two more digits (e.g., 11-22-33). It plays a crucial role in facilitating bank transfers, direct debits, and other financial operations. Each sort code corresponds to a particular branch or location, ensuring that funds are directed accurately.


What are two Java primitive types store floating-point numbers?

In Java, you can use either a float or a double


What is the largest six-digit number using the digits 123456?

You get the largest number if you sort the digits, from largest to smallest.


What bank sort code is 004386?

This sort code is invalid. A sort code cannot begin with '00'. The lowest digits a sort code can begin with is '01'.


Sample of heap sort in java using string?

because of the gravity of the earth


What are the types and functions of libraries in Java?

Libraries are prewritten pieces of java code that are present to help us write code for our applications easily and effectively. for ex: Collections.sort() is a library function in Java that can be used to sort collections. This can be used instead of the programmer writing his own custom implementation of sort.


Is the number 10 one or two digits?

two digits