Write a java program using Dialog boxes that prompt the user

Write a java program using Dialog boxes that prompt the user to input five floating point decimal numbers. the program should then add the five numbers, find the average, convert sum and average to the nearest integer, and print the numbers, sum and average.

Solution

The java program using Dialog boxes that prompt the user to input five floating point decimal numbers :-


import java.lang.*;


import javax.swing.JOptionPane;

class Example

{
  
public static void main (String[ ] args)
  
{
  
  
String value1,value2,value3,value4,value5 ;

float f1,f2,f3,f4,f5 ;

float sum ;
  
float Average ;

  

// Read input String from dialog box

value1 = JOptionPane.showInputDialog(\"Enter the floating point decimal number\");
  
f1 = Float.parseFloat(value1); // Convert String to float
  
  

value2 = JOptionPane.showInputDialog(\"Enter the floating point decimal number\");

f2 = Float.parseFloat(value2); // Convert String to float

value3 = JOptionPane.showInputDialog(\"Enter the floating point decimal number\");
  
f3 = Float.parseFloat(value3); // Convert String to float

value4 = JOptionPane.showInputDialog(\"Enter the floating point decimal number\");

f4 = Float.parseFloat(value4); // Convert String to float

  

value5 = JOptionPane.showInputDialog(\"Enter the floating point decimal number\");

f5 = Float.parseFloat(value5); // Convert String to float
  

sum = f1+f2+f3+f4+f5 ;

  

Average = sum/5 ;

  

System.out.println(f1) ;

System.out.println(f2) ;

System.out.println(f3) ;

System.out.println(f4) ;
  
System.out.println(f5) ;

System.out.println(\"Math.round(\" + sum + \")=\" + Math.round(sum));

System.out.println(\"Math.round(\" + Average + \")=\" + Math.round(Average));


}

}

Write a java program using Dialog boxes that prompt the user to input five floating point decimal numbers. the program should then add the five numbers, find th
Write a java program using Dialog boxes that prompt the user to input five floating point decimal numbers. the program should then add the five numbers, find th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site