[英]How to use JOptionPane.showMessageDialog once in the prograde
How many times have you used the statement: JOptionPane.showMessageDialog? 您使用过几次语句:JOptionPane.showMessageDialog? If your answer is more than once go back and revise your code so that you only use ONE JOptionPane.showMessageDialog 如果答案不止一次,请返回并修改代码,以便仅使用一个JOptionPane.showMessageDialog。
Hint: consider using a variable of type String named output 提示:请考虑使用名为输出的字符串类型的变量
Code 码
if(credit >= 120) 如果(贷方> = 120)
{
JOptionPane.showMessageDialog(null,"You've graduated!");
}//end if
else if(credit >= 90)
{
JOptionPane.showMessageDialog(null,"You're a senior.");
}//end if
else if(credit >= 60)
{
JOptionPane.showMessageDialog(null,"You're a junior.");
}//end if
else if(credit >= 30)
{
JOptionPane.showMessageDialog(null,"You're a sophomore.");
}//end if
else if(credit >=0)
{
JOptionPane.showMessageDialog(null,"You're a freshment.");
}//end if
else
{
JOptionPane.showMessageDialog(null,"invalid input");
使用if-else语句生成要显示的String,然后使用一行使用String调用showMessageDialog()
。
//don't forget to import the JOptionPane library //不要忘记导入JOptionPane库
//also I have no clue how you used your credit variable public class prograde { public void showJoption(String position) { JOptionPane.showMessageDialog(null, position); //同样,我也不知道您如何使用信用变量public class prograde {public void showJoption(String position){JOptionPane.showMessageDialog(null,position); } }
public static void main(String[] args)
{
//this is the class object that you can use to call the showJoption() method.
prograde display = new prograde();
if(credit >= 120)
{
display.showJoption("You've graduated!");
}
else if (credit >= 90)
{
display.showJoption("You're a senior.");
}
else if (credit >= 60)
{
display.showJoption("You're a junior.");
}
else if (credit >= 30)
{
display.showJoption("You're a sophomore.");
}
else if (credit >= 0)
{
display.showJoption("You're a freshment.");
}
else {
display.showJoption("invalid input");
}
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.