-3
package AlgoritmosII;
import javax.swing.*;
public class Exercicio //BubbleSort
{
public static void main(String args[])
{
int troca, fim, i, aux, k;
int tamanho = Integer.parseInt(JOptionPane.showInputDialog("informe o tamanho do vetor"));
int vetorOrdenar[] = new int[tamanho];
for (i=0;i<=tamanho;i++) {
vetorOrdenar[i] = Integer.parseInt(JOptionPane.showInputDialog("Informe os " +tamanho+ " valores do vetor:"));
}
troca = 1;
fim = tamanho - 1;
while(troca==1)
{
troca = 0;
for(i=0; i<fim;i++)
{
if (vetorOrdenar[i] > vetorOrdenar[i+1])
{
aux = vetorOrdenar[i];
vetorOrdenar[i] = vetorOrdenar[i+1];
vetorOrdenar[i+1]=aux;
troca = 1;
}
}
fim = fim - 1;
}
for (k=0;k<=tamanho;k++){
JOptionPane.showMessageDialog(null,vetorOrdenar[i]);
i++;
}
}
}
My goal would be to ask the user to say the size of the vector and the values that would be placed on it, after that it would be placed in ascending order, in the end it should show the ordered form of the vector.