Hi everyone whenever i press other keys other than \'y\', it triggersyes(Enter t
ID: 3613453 • Letter: H
Question
Hi everyone whenever i press other keys other than 'y', it triggersyes(Enter the temperature). how do i set it to 'y' rather thanusing {while(charAns!='n') i understand the correct way is to setit y equals to yes,how do i set this command....? *i tried {while(charAns >= 'y') it worked but it is not the equals(=) command..it isgreater than or equals.. thank you & regards... 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 <= 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);
if(++count>=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);
}
}
Hi everyone whenever i press other keys other than 'y', it triggersyes(Enter the temperature). how do i set it to 'y' rather thanusing {while(charAns!='n') i understand the correct way is to setit y equals to yes,how do i set this command....? *i tried {while(charAns >= 'y') *i tried {while(charAns >= 'y') it worked but it is not the equals(=) command..it isgreater than or equals.. thank you & regards... 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 <= 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);
if(++count>=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);
}
}
Explanation / Answer
please rate - thanks this will make it continue only if a y or a Y is entered,everything else will be considered no import javax.swing.JOptionPane; public class Untitled { 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=='y'||charAns=='Y'); 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.