import javax.swing.JOptionPane; //importando a classe JoptionPane
public class test // declaração da classe
public class test // declaração da classe
ImparesParesMaiorMenor{ //abertura da class
public static void main(String[] args) // declaração da função principal
public static void main(String[] args) // declaração da função principal
{ // abertura da função main
String saidaindpar = "Indices que possuem valores pares >> ";
String saidaindimpar = "Indices que possuem valores impares >> ";
String elementos = "Valores fornecidos >> ";
String valormaior = "O valor maior é >>";
String valormenor = "O valor menor é >>";
String saidafinal = "";
String saidaindpar = "Indices que possuem valores pares >> ";
String saidaindimpar = "Indices que possuem valores impares >> ";
String elementos = "Valores fornecidos >> ";
String valormaior = "O valor maior é >>";
String valormenor = "O valor menor é >>";
String saidafinal = "";
int array[] = new int[4];
int teste1, teste2;
int teste1, teste2;
for(int i = 0;i < 4;i ++)
{ // abertura da estrutura for
array[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"Entre com o valor " + (i+1) ));
elementos = elementos + " - " + array[i];
} //fechamento da estrutura for
for(int i = 0;i < 4;i ++)
{// abertura da estrutura for
if(array[i] % 2 == 0)
{ //abertura do if
saidaindpar = saidaindpar + " - " + array[i];
} // fechamento do if
else
{ // abertura do estrutura else
saidaindimpar = saidaindimpar + " - " + array[i];
}
} // fechamento da estrutura for
{ // abertura da estrutura for
array[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"Entre com o valor " + (i+1) ));
elementos = elementos + " - " + array[i];
} //fechamento da estrutura for
for(int i = 0;i < 4;i ++)
{// abertura da estrutura for
if(array[i] % 2 == 0)
{ //abertura do if
saidaindpar = saidaindpar + " - " + array[i];
} // fechamento do if
else
{ // abertura do estrutura else
saidaindimpar = saidaindimpar + " - " + array[i];
}
} // fechamento da estrutura for
teste1=array[0];
teste2=array[0];
for(int i = 0;i < 4;i ++)
{
if (array[i] > teste1)
{
teste1=array[i];
System.out.println("Valor teste1 - " + teste1);
}
if (array[i] < teste2)
{
teste2=array[i];
System.out.println("Valor teste1 - " + teste2);
}
}
valormaior = valormaior + " - " + teste1;
valormenor = valormenor + " - " + teste2;
saidafinal = saidafinal + elementos + "\n";
saidafinal = saidafinal + saidaindpar + "\n";
saidafinal = saidafinal + saidaindimpar + "\n";
saidafinal = saidafinal + valormaior + "\n";
saidafinal = saidafinal + valormenor + "\n";
JOptionPane.showMessageDialog(null, saidafinal);
} // fechamento da função main
} //fechamento da classe
Nenhum comentário:
Postar um comentário