Skip to content

Instantly share code, notes, and snippets.

@liezl200
Forked from anonymous/NumberOrdering.java
Created August 11, 2016 22:14
Show Gist options
  • Save liezl200/991488470c4578c634c16bfb9974adb8 to your computer and use it in GitHub Desktop.
Save liezl200/991488470c4578c634c16bfb9974adb8 to your computer and use it in GitHub Desktop.
// initial solution (before discussion)
import java.util.*;
public class NumberOrdering {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
ArrayList<Integer> values = new ArrayList<Integer>();
int input;
int a, b, t;
do{
System.out.println("Number?");
input = s.nextInt();
values.add(input);
System.out.println(values);
if(input == 1){
break;
}
}while(input != ""); //can't have integer and string together
//result array
ArrayList<Integer> result = new ArrayList<Integer>();
for(a = 1; a < result; a++){ //can't have array list and integer together
for(b = size-1; b >= a; b--){
if(values[b-1] > values[b]){
t = values[b-1];
values[b-1] = values[b];
values[b] = t;
}
}
}
//print sorted result array
System.out.println(" " + result[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment