Calcular Promedio con Metodos

import javax.swing.JOptionPane;
public class Prueba_9_Junio {
   
    public static double  num1;
    public static double  num2;
    public static double  num3;
    public static double  promedio;
   
    public static void main(String[] args) {
        int cont= 1;
       
            try{
                while(cont <= 1)
                {
                    pedirNum1();
                    pedirNum2();
                    pedirNum3();
                    calc_promedio();
                    cont++;
                }
            }catch(Exception e)
            {
                JOptionPane.showMessageDialog(null, "Ingrese un numero");
            }
       
    }
   
    public static void pedirNum1()
    {
         
        String t1 = JOptionPane.showInputDialog("Ingrese un primer numero:");
        int seguir=1;
        while( seguir != 0)
            {
            try{
            num1 = Integer.parseInt(t1);
            seguir = 1;
            if( num1 > 0 && num1 <= 100){
                   
            }else
            {
                JOptionPane.showMessageDialog( null, "Escriba un numero del 0 al 100");
            }
          }catch(NumberFormatException e)
          {
              JOptionPane.showMessageDialog(null, "Error ingrese valores numericos!!");
            }
        }
   
    }
   
    public static  void pedirNum2()
    {
        String t2 = JOptionPane.showInputDialog("Ingrese un segundo numero:");
        try{
           
            num2 = Integer.parseInt(t2);
            if( num2 > 0 && num2 <= 100){
           
            }else{
                JOptionPane.showMessageDialog( null, "Escriba un numero del 0 al 100");
            }
        }catch(NumberFormatException e){
           JOptionPane.showMessageDialog(null, "ERROR \nIngrese un numero!!");
        }
       
    }
   
    public static void pedirNum3()
    {
        String t3 = JOptionPane.showInputDialog("Ingrese un tercer numero:");
        try{
           num3 = Integer.parseInt(t3);
           if( num3 > 0 && num3 <= 100){
           
            }else{
                JOptionPane.showMessageDialog( null, "Escriba un numero del 0 al 100");
            }
        }catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null, "ERROR \nIngrese un numero!!");
        }
       
       
    }
   
    public static void calc_promedio()
    {
        promedio = (num1 + num2 + num3) / 3;
        JOptionPane.showMessageDialog(null,"El promedio es: " + promedio);
    }
}

Comentarios

Entradas más populares de este blog

Elevar un numero a la potencia 2 y al cubo

Tabla descendente de numeros