Java:如何打印矢量?
import java.util.Scanner;
public class Ed04VetorOrdenado {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
int vet[] = new int[10];
System.out.println("Digite 10 numeros:");
for (int i = 0; i < vet.length; i++) {
vet[i] = entrada.nextInt();
}
System.out.print("Vetor ordenado: ");
ordenar(vet);
}
// Buble sort function
static void ordenar(int[] v) {
int troca;
for (int i = 0; i < v.length; i++) {
for (int j = i + 1; j < v.length; j++) {
if (v[i] > v[j]) {
troca = v[j];
v[j] = v[i];
v[i] = troca;
}
}
System.out.print(v[i] + ", ");
}
}
}
我想在 FOR 之外打印。类似的
System.out.print(v);