-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunAlpha.java
51 lines (37 loc) · 859 Bytes
/
RunAlpha.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class RunAlpha {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean swapped = false;
String word;
char[] letters;
int index = 0;
//get user input
System.out.println("Input a value for the String: ");
word=input.next();
letters = word.toCharArray();
//sort algorithm
do
{
swapped = false;
for(index = 0; index < (letters.length -1); index++)
{
if(letters[index] > letters[index+1])
{
char temp = letters[index+1];
letters[index+1]=letters[index];
letters[index] = temp;
swapped = true;
}
}
}while(swapped == true);
//Print sorted array
for(index = 0; index<letters.length; index++)
{
System.out.println(letters[index]);
}
}
}