• Matéria: Informática
  • Autor: mateus77irala
  • Perguntado 7 anos atrás

Faça um Programa que leia 4 notas, mostre as notas e a média na tela em java.

Respostas

respondido por: Ally85
2

Resposta:

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package media;

import javax.swing.JOptionPane;

/**

*

* @author Alix

*/

public class Media {

   /**

    * @param args the command line arguments

    */

   public static void main(String[] args) {

       

      float[] nota = {0,0,0,0,0};

      int x;

      float t, media=0;  

       

      for(x=1;x<=4;x++){

          String m = JOptionPane.showInputDialog(null,"Insira a "+x+"º nota");

          t = Integer.parseInt(m);

          nota[x] = t;

      }    

       

      for(x=1;x<=4;x++){

         media = media + nota[x];

      }

       

      media = media/4;

       

      JOptionPane.showMessageDialog(null,"As notas foram: \nNota 1: "+nota[1]+"\nNota 2: "+nota[2]+"\nNota 3: "+nota[3]+"\nNota 4: "+nota[4]+"\n\nA média é "+media);

   }

   

}

Explicação:

Perguntas similares