Ajuda com matriz tipo vetor (RESOLVIDO)

2 respostas
A

Estou tentando fazer esse programa: Ler 20 elementos (valores reais) para temperaturas em graus Celsius em uma matriz A de uma dimensão do tipo vetor. O programa deverá apresentar a menor, a maior e a média das temperaturas lidas.

Iniciei assim:

public static void main(String[] args) {
     double m [] = new double [15];
     double n [] = new double [15];
     String snum,s= "";
     double num;

     for (int i=0;i<m.length;i++)
     {
      snum = JOptionPane.showInputDialog("digite o valor");
      num = Double.parseDouble(snum);
      m[i] = num;
     }

Mas não estou sabendo como continuar, se caso alguem souber…

2 Respostas

U
public static void main(String[] args) {
    double array [] = new double [20];
    double sum = 0, higher = 0; lower = 99;

     for (int i= 0; i < array.length; i++) {
     	array[i] = Double.parseDouble(JOptionPane.showInputDialog("Input a value:"));
      	sum += array[i];

	if(array[i] > higher) higher = array[i];
	if(array[i] < lower) lower = array[i];
     }

	JOptionPane.showMessageDialog(null, sum / array.length);
	JOptionPane.showMessageDialog(null, ""+higher+"\t"+lower+"");
  }

Espero que tenha ajudado.
Att, Utroz.

A

Muito obrigada Utroz, mim ajudou muito mesmo.

Criado 9 de junho de 2011
Ultima resposta 10 de jun. de 2011
Respostas 2
Participantes 2