Created
March 13, 2014 06:09
-
-
Save JorgeOlvera/9522656 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/*3. Integer sort: Write a method integerSort that takes from standard input a | |
sequence of integers that are between 0 and 99 and prints the same | |
integers in sorted order on standard output. For example, presented with | |
the input sequence*/ | |
import java.io.*; | |
import java.util.Scanner; | |
public class intergerSort{ | |
public static void main(String[] args){ | |
Scanner input = new Scanner(System.in); | |
// Aceptar input | |
int[] myArray; | |
int[] arraySorteao; | |
System.out.println("Introduce length of array"); | |
int extension = input.nextInt(); | |
int[] myArray = new int [extension]; | |
//Hacer un array con el input | |
System.out.println("Introduce array values. Please introduce a value between 0 and 99"); | |
for (int i=0; i<myArray.length; i{ | |
checkLength = input.nextInt(); | |
if (checkLength >= 0 || checkLength <= 99){ | |
myArray[i] = checkLength | |
} | |
else{ | |
System.out.println("Please introduce a value between 0 and 99") | |
} | |
} | |
arraySorteao = michaelBubble(myArray); | |
System.out.println(arraySorteao); | |
//Mandar el array a un nuevo method | |
public static int[] michaelBubble(int[] myArray){ | |
int array[] = myArray[]; | |
boolean flag = true; | |
int temp; | |
while(flag){ | |
flag = false; | |
for(int i = 0; i < array.length-1; i++){ | |
if(array[i] > array[i+1]){ | |
temp = array[i]; | |
array[i] = array[i+1]; | |
array[i+1] = temp; | |
flag = true; | |
} | |
} | |
} | |
return array; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment