Hi everyone How do i modify this program so that after 3 iterations,the programe
ID: 3613429 • Letter: H
Question
Hi everyoneHow do i modify this program so that after 3 iterations,the programexits without asking the user if he wants to continue theprgram.
import javax.swing.JOptionPane;
public class Ques3
{
public static void main (String args[])
{
int temp;
String tempString;
String contString;
char charAns;
do
{
tempString = JOptionPane.showInputDialog(null, "Enter thetemperature:",
"Input",JOptionPane.QUESTION_MESSAGE);
temp = Integer.parseInt(tempString);
if (temp < 10 )
JOptionPane.showMessageDialog(null,"Too Cold", "Output",
JOptionPane.INFORMATION_MESSAGE);
else if (temp >= 10 && temp <= 20)
JOptionPane.showMessageDialog(null,"Average", "Output",
JOptionPane.INFORMATION_MESSAGE);
else if (temp >= 21 && temp <= 30)
JOptionPane.showMessageDialog(null, "Hot", "Output",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Too Hot", "Output",
JOptionPane.INFORMATION_MESSAGE);
contString =
JOptionPane.showInputDialog(null, "Would you like to continue(y/n):",
"Input",JOptionPane.QUESTION_MESSAGE);
charAns = contString.charAt(0);
}while (charAns !='n');
System.exit(0);
}
}
pls help me...tq & rgds Hi everyone
How do i modify this program so that after 3 iterations,the programexits without asking the user if he wants to continue theprgram.
import javax.swing.JOptionPane;
public class Ques3
{
public static void main (String args[])
{
int temp;
String tempString;
String contString;
char charAns;
do
{
tempString = JOptionPane.showInputDialog(null, "Enter thetemperature:",
"Input",JOptionPane.QUESTION_MESSAGE);
temp = Integer.parseInt(tempString);
if (temp < 10 )
JOptionPane.showMessageDialog(null,"Too Cold", "Output",
JOptionPane.INFORMATION_MESSAGE);
else if (temp >= 10 && temp <= 20)
JOptionPane.showMessageDialog(null,"Average", "Output",
JOptionPane.INFORMATION_MESSAGE);
else if (temp >= 21 && temp <= 30)
JOptionPane.showMessageDialog(null, "Hot", "Output",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Too Hot", "Output",
JOptionPane.INFORMATION_MESSAGE);
contString =
JOptionPane.showInputDialog(null, "Would you like to continue(y/n):",
"Input",JOptionPane.QUESTION_MESSAGE);
charAns = contString.charAt(0);
}while (charAns !='n');
System.exit(0);
}
}
pls help me...tq & rgds
Explanation / Answer
please rate - thanks add a counter import javax.swing.JOptionPane; public class Ques3 { public static void main (String args[]) { int temp,count=0; String tempString; String contString; char charAns; do { tempString = JOptionPane.showInputDialog(null, "Enter thetemperature:", "Input",JOptionPane.QUESTION_MESSAGE); temp = Integer.parseInt(tempString); if (temp < 10 ) JOptionPane.showMessageDialog(null,"Too Cold", "Output", JOptionPane.INFORMATION_MESSAGE); else if (temp >= 10 && temp = 21 && temp =3) System.exit(0); contString = JOptionPane.showInputDialog(null, "Would you like to continue(y/n):", "Input",JOptionPane.QUESTION_MESSAGE); charAns = contString.charAt(0); }while (charAns !='n'); System.exit(0); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.