While

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View While as PDF for free.

More details

  • Words: 106
  • Pages: 1
import javax.swing.*; public class while{ public static void main(string[] args){ final int maxnum = 4; string message = "this program will ask you to enter " + maxnum + " numbers."; joptionpane.showmessagedialog(null,message,"while loop", joptionpane.information_message); double total=0; int count=1; string msg=null; while(count <= maxnum){ switch(count){ case 1: msg = "first"; break; case 2: msg = "second"; break; case 3: msg = "third"; break; case 4: msg = "fourth"; break; } string s = joptionpane.showinputdialog("enter " + msg + " number: "); double num = double.parsedouble(s); total +=num; ++count; } joptionpane.showmessagedialog(null,"the total of the " + maxnum + " numbers is " + total, "result",joptionpane.information_message); system.exit(0); }

}

Related Documents

While
November 2019 30
While
November 2019 29
While
June 2020 17
Do-while
November 2019 32
Do While
June 2020 16
While I.docx
December 2019 10