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); }
}