-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathVetorCircular.java
More file actions
33 lines (29 loc) · 1.07 KB
/
VetorCircular.java
File metadata and controls
33 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class VetorCircular {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] listaEntrada = input.nextLine().split(" ");
int quantidadeElementos = input.nextInt();
int[] arrayInteiros = new int[listaEntrada.length];
for (int i = 0; i < listaEntrada.length; i++) {
arrayInteiros[i] = Integer.parseInt(listaEntrada[i]);
}
System.out.print(vetorCircular(arrayInteiros, quantidadeElementos));
}
private static String vetorCircular(int[] vetor, int quantidadeElementos) {
String saida = "";
int tamanho = 0;
int indice = 0;
while (tamanho < quantidadeElementos) {
if(indice == vetor.length - 1) {
saida += vetor[indice] + " ";
indice = 0;
}
saida += vetor[indice] + " ";
tamanho = saida.replace(" ", "").length();
indice++;
}
saida = saida.substring(0,saida.length() - 1);
return saida;
}
}