aaaaa
unknown
java
2 years ago
1.0 kB
7
Indexable
import java.util.*; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int[] vetor = new int[10]; int indice = 0; System.out.println("Digite valores para vetor"); while(indice < vetor.length + 1) { try { int sup = input.nextInt(); if(sup == 0){ vetor[indice] = sup; break; } else { vetor[indice] = sup; indice++; } } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Vetor cheio!"); break; } catch (InputMismatchException e) { System.out.println("Informe um valor numerico"); break; } } System.out.println("Valores inseridos:"); for(int i = 0; i < indice; i++){ System.out.println(vetor[i]); } } }
Editor is loading...