The following program demonstrates how to Arrange Two Characters in Ascending Order in Java.
In order to arrange characters in ascending order, we need the ASCII values of these characters. For this purpose, we assign these characters to integer variables. Then we can compare them using if statement.
public class Exercise4
{
public static void main(String[] args) {
char c1, c2;
int n1, n2;
c1='a';
c2='h';
n1=c1;
n2=c2;
if(n1>n2)
System.out.println(c2+", "+c1);
else
System.out.println(c1+", "+c2);
}
}
Output

Further Reading
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
