SlideShare a Scribd company logo
1 of 3
Download to read offline
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));
}
}

More Related Content

Similar to Write a java program using Dialog boxes that prompt the user to inpu.pdf

1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
thuhiendtk4
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30
myrajendra
 

Similar to Write a java program using Dialog boxes that prompt the user to inpu.pdf (20)

CSL101_Ch1.pptx
CSL101_Ch1.pptxCSL101_Ch1.pptx
CSL101_Ch1.pptx
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
a basic java programming and data type.ppt
a basic java programming and data type.ppta basic java programming and data type.ppt
a basic java programming and data type.ppt
 
Javadocx j option pane
Javadocx j option paneJavadocx j option pane
Javadocx j option pane
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30
 
Intro f# functional_programming
Intro f# functional_programmingIntro f# functional_programming
Intro f# functional_programming
 
Java small steps - 2019
Java   small steps - 2019Java   small steps - 2019
Java small steps - 2019
 
Function
FunctionFunction
Function
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Comp102 lec 4
Comp102   lec 4Comp102   lec 4
Comp102 lec 4
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
Savitch Ch 04
Savitch Ch 04Savitch Ch 04
Savitch Ch 04
 
Savitch Ch 04
Savitch Ch 04Savitch Ch 04
Savitch Ch 04
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxChapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
 
C function
C functionC function
C function
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 

More from calderoncasto9163

JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
calderoncasto9163
 
Let us roll a die twice. The number from the first throw is denoted .pdf
Let us roll a die twice. The number from the first throw is denoted .pdfLet us roll a die twice. The number from the first throw is denoted .pdf
Let us roll a die twice. The number from the first throw is denoted .pdf
calderoncasto9163
 
in html 1 A Header with font size ranging from h4 to h1 with at l.pdf
in html 1 A Header with font size ranging from h4 to h1 with at l.pdfin html 1 A Header with font size ranging from h4 to h1 with at l.pdf
in html 1 A Header with font size ranging from h4 to h1 with at l.pdf
calderoncasto9163
 
Explain the answers in sufficient details i.e show the work ace Wha.pdf
Explain the answers in sufficient details i.e show the work ace Wha.pdfExplain the answers in sufficient details i.e show the work ace Wha.pdf
Explain the answers in sufficient details i.e show the work ace Wha.pdf
calderoncasto9163
 
Describe the difference between a. The pulmonary and systemic circula.pdf
Describe the difference between a. The pulmonary and systemic circula.pdfDescribe the difference between a. The pulmonary and systemic circula.pdf
Describe the difference between a. The pulmonary and systemic circula.pdf
calderoncasto9163
 
Describe some effects that cybertechnology has had so far for our se.pdf
Describe some effects that cybertechnology has had so far for our se.pdfDescribe some effects that cybertechnology has had so far for our se.pdf
Describe some effects that cybertechnology has had so far for our se.pdf
calderoncasto9163
 
Choose a deployment platform that allows for the implementation o.pdf
Choose a deployment platform that allows for the implementation o.pdfChoose a deployment platform that allows for the implementation o.pdf
Choose a deployment platform that allows for the implementation o.pdf
calderoncasto9163
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
calderoncasto9163
 
Answer die following questions with short answers Explain the d.pdf
Answer die following questions with short answers  Explain the d.pdfAnswer die following questions with short answers  Explain the d.pdf
Answer die following questions with short answers Explain the d.pdf
calderoncasto9163
 

More from calderoncasto9163 (20)

LOS At the time of her death on September 4, 2015, Alicia held the .pdf
LOS At the time of her death on September 4, 2015, Alicia held the .pdfLOS At the time of her death on September 4, 2015, Alicia held the .pdf
LOS At the time of her death on September 4, 2015, Alicia held the .pdf
 
Match the following terms with the definitions given belowTerms Gi.pdf
Match the following terms with the definitions given belowTerms Gi.pdfMatch the following terms with the definitions given belowTerms Gi.pdf
Match the following terms with the definitions given belowTerms Gi.pdf
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 
Let us roll a die twice. The number from the first throw is denoted .pdf
Let us roll a die twice. The number from the first throw is denoted .pdfLet us roll a die twice. The number from the first throw is denoted .pdf
Let us roll a die twice. The number from the first throw is denoted .pdf
 
Is there relationship between having a high school education and kno.pdf
Is there relationship between having a high school education and kno.pdfIs there relationship between having a high school education and kno.pdf
Is there relationship between having a high school education and kno.pdf
 
In a survey, 600 mothers and fathers were asked about the importance.pdf
In a survey, 600 mothers and fathers were asked about the importance.pdfIn a survey, 600 mothers and fathers were asked about the importance.pdf
In a survey, 600 mothers and fathers were asked about the importance.pdf
 
in html 1 A Header with font size ranging from h4 to h1 with at l.pdf
in html 1 A Header with font size ranging from h4 to h1 with at l.pdfin html 1 A Header with font size ranging from h4 to h1 with at l.pdf
in html 1 A Header with font size ranging from h4 to h1 with at l.pdf
 
Identify these monomers (general classification). Are the monomers h.pdf
Identify these monomers (general classification).  Are the monomers h.pdfIdentify these monomers (general classification).  Are the monomers h.pdf
Identify these monomers (general classification). Are the monomers h.pdf
 
How is the Internet come about How was the World Wide Web ( WWW .pdf
How is the Internet come about  How was the World Wide Web ( WWW .pdfHow is the Internet come about  How was the World Wide Web ( WWW .pdf
How is the Internet come about How was the World Wide Web ( WWW .pdf
 
Explain the answers in sufficient details i.e show the work ace Wha.pdf
Explain the answers in sufficient details i.e show the work ace Wha.pdfExplain the answers in sufficient details i.e show the work ace Wha.pdf
Explain the answers in sufficient details i.e show the work ace Wha.pdf
 
Each figure is an isometry image of the figure at the right. Tell whe.pdf
Each figure is an isometry image of the figure at the right. Tell whe.pdfEach figure is an isometry image of the figure at the right. Tell whe.pdf
Each figure is an isometry image of the figure at the right. Tell whe.pdf
 
E. None of the above.E. Actually, they differ in all of these ways.pdf
E. None of the above.E. Actually, they differ in all of these ways.pdfE. None of the above.E. Actually, they differ in all of these ways.pdf
E. None of the above.E. Actually, they differ in all of these ways.pdf
 
Describe the difference between a. The pulmonary and systemic circula.pdf
Describe the difference between a. The pulmonary and systemic circula.pdfDescribe the difference between a. The pulmonary and systemic circula.pdf
Describe the difference between a. The pulmonary and systemic circula.pdf
 
Cross a homozygous running, heterozygous black mouse with a waltzing.pdf
Cross a homozygous running, heterozygous black mouse with a waltzing.pdfCross a homozygous running, heterozygous black mouse with a waltzing.pdf
Cross a homozygous running, heterozygous black mouse with a waltzing.pdf
 
Describe some effects that cybertechnology has had so far for our se.pdf
Describe some effects that cybertechnology has had so far for our se.pdfDescribe some effects that cybertechnology has had so far for our se.pdf
Describe some effects that cybertechnology has had so far for our se.pdf
 
Choose a deployment platform that allows for the implementation o.pdf
Choose a deployment platform that allows for the implementation o.pdfChoose a deployment platform that allows for the implementation o.pdf
Choose a deployment platform that allows for the implementation o.pdf
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
 
A range of values estimated to have a high probably of containing th.pdf
A range of values estimated to have a high probably of containing th.pdfA range of values estimated to have a high probably of containing th.pdf
A range of values estimated to have a high probably of containing th.pdf
 
A thrown lump of clay hits a block in mid air and sticks to it. what.pdf
A thrown lump of clay hits a block in mid air and sticks to it. what.pdfA thrown lump of clay hits a block in mid air and sticks to it. what.pdf
A thrown lump of clay hits a block in mid air and sticks to it. what.pdf
 
Answer die following questions with short answers Explain the d.pdf
Answer die following questions with short answers  Explain the d.pdfAnswer die following questions with short answers  Explain the d.pdf
Answer die following questions with short answers Explain the d.pdf
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 

Recently uploaded (20)

FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 

Write a java program using Dialog boxes that prompt the user to inpu.pdf

  • 1. 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
  • 2. 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)); }
  • 3. }