You are on page 1of 2

3.

(b): Write a code to take Input 5 numbers from user


(JOptionPane.showInputDialog() )and calculate average of those five number.
SOLUTION:

import javax.swing.*;

public class Average {

public static void main(String abc[])

String a1=JOptionPane.showInputDialog("enter first value",null);

int b1=Integer.parseInt(a1);

System.out.println("first value= "+b1);

String a2=JOptionPane.showInputDialog("enter second value",null);

int b2=Integer.parseInt(a2);

System.out.println("second value= "+b2);

String a3=JOptionPane.showInputDialog("enter third value",null);

int b3=Integer.parseInt(a3);

System.out.println("third value= "+b3);

String a4=JOptionPane.showInputDialog("enter forth value",null);

int b4=Integer.parseInt(a4);

System.out.println("forth value= "+b4);

String a5=JOptionPane.showInputDialog("enter fifth value",null);

int b5=Integer.parseInt(a5);

System.out.println("fifth value= "+b5);

double avg=(b1+b2+b3+b4+b5)/5;

System.out.println("average= "+avg);
}

You might also like