-
Notifications
You must be signed in to change notification settings - Fork 0
/
Run.java
52 lines (39 loc) · 890 Bytes
/
Run.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
52
import java.util.Scanner;
public class Run {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean swapped = false;
int[] numbers = new int[6];
int index = 0;
//get user input
while(index < numbers.length)
{
System.out.println("Input a value for number "+(index+1)+": ");
numbers[index]=input.nextInt();
index++;
}
//sort algorithm
do
{
swapped = false;
for(index = 0; index < (numbers.length -1); index++)
{
if(numbers[index] > numbers[index+1])
{
int temp = numbers[index+1];
numbers[index+1]=numbers[index];
numbers[index] = temp;
swapped = true;
}
}
}while(swapped == true);
//Print sorted array
for(index = 0; index<numbers.length; index++)
{
System.out.println(numbers[index]);
}
}
}