Srs, bom dia!
Tenho um array onde usuário determina o tamanho. Meu objetivo e determinar o menor entre os valores informados. Entendo que estou com algum erro na variável que controle a posição do meu vetor. Segue mensagem que é impressa no final da execução do programa.
Se alguém puder me ajudar, agradeço antecipadamente. Bom dia a todos.
Exception in thread ?main? java.lang.ArrayIndexOutOfBoundsException:
public class Exec_511
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
String Snum =
JOptionPane.showInputDialog( "Posições do Vetor" );
int num = Integer.parseInt( Snum );
int[] v = new int[ num ];
int indice=0;
System.out.printf( "%s\n%s\n",
"Enter the integer numbers.",
"On Windows type <Ctrl> z the press Enter:" );
while( input.hasNext() )
{
v[indice] = input.nextInt();
indice ++;
}
int menor = v[0];
for( int i=0; i<= v.length; i++ )
{
if( v[i] < menor )
{
menor = v[i];
}
}
System.out.printf("Menor%d:", menor );
}
}