-
-
Save liezl200/991488470c4578c634c16bfb9974adb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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