Gente Boa Tarde.
Estou meio com urgência então nem vou me aprensentar.
Mas fiz um programa (inda to na facul :D) fazendo com que qualquer valor digitado retornasse os mesmos em ordem crescente ou decrescente (dependendo da escolha do usuário) e o professor pediu como um “extra” para que os valores retornados no vetor aparecessem em uma tabela, mas ta impossivel de eu consiguir isso.
Aki vai como esta por enquanto:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%
String nome = request.getParameter("nome");
String op = request.getParameter("op");
String vet[] = nome.split(",");
int vet1[] = new int[vet.length];
for(int i = 0 ;i<vet.length;i++)
{
vet1[i] = Integer.parseInt(vet[i]);
}
for (int j=0; j <vet1.length;j++)
{
if (op.equals("1"))
{
for(int i=0 ;i<vet1.length-1;i++)
{
if (vet1[i] > vet1[i+1])
{
int aux = vet1[i];
vet1[i] = vet1[i+1];
vet1[i+1] = aux;
}
}
}
if (op.equals("2"))
{
for(int i=0 ;i<vet1.length-1;i++)
{
if (vet1[i] < vet1[i+1])
{
int aux = vet1[i];
vet1[i] = vet1[i+1];
vet1[i+1] = aux;
}
}
}
}
for (int i= 0; i<vet1.length;i++)
{
out.println("<br>Vetor ["+i+"]="+vet1[i]);
}
%>
</body>
</html>
Obrigado