-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise03_08.java
More file actions
52 lines (46 loc) · 1.44 KB
/
Copy pathExercise03_08.java
File metadata and controls
52 lines (46 loc) · 1.44 KB
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
52
package Chapter3;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
import java.util.Arrays;
/**
*
* @author jorda
*/
public class Exercise03_08 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int iThreeDigitNumber = input.nextInt();
int iFirst, iSecond, iThird;
//Seperate the digits
iThird = iThreeDigitNumber % 10;
iThreeDigitNumber /= 10;
iSecond = iThreeDigitNumber % 10;
iThreeDigitNumber /= 10;
iFirst = iThreeDigitNumber % 10;
//assign to array:
//int[] digitArray = new int[3];
int[] digitArray = {iFirst,iSecond,iThird};
//bubble sort:
boolean swapped = true;
int iLenList = 3;
int temp;
while (iLenList > 0 && swapped){
swapped = false;
for (int i = 0; i<3; i++){
if (digitArray[i] > digitArray[i+1]){
swapped = true;
temp = digitArray[i];
digitArray[i] = digitArray[i+1];
digitArray[i+1] = temp;
}
iLenList -= 1;
}
}
//debug
System.out.println(Arrays.toString(digitArray));
}
}