我是编程的新手 - 我正在学习Java.我正在尝试使用JOptionPane来处理if/else语句.除了陈述之外,一切正常.我只得到声明"停止并获取燃气!" 无论输入什么答案(是或否).
任何帮助,将不胜感激!
//This program determine if I have to stop for gas on the way in to work.
import javax.swing.JOptionPane;
import java.util.*;
public class GasIndicator
{
public static void main(String[] args)
{
String answer;
String outputStr1;
String outputStr2;
answer =
JOptionPane.showInputDialog ( "Do you have at least an eighth tank of gas? yes or no " );
outputStr1 = "You can drive straight to work";
outputStr2 = "Stop and get gas!";
if (answer == "yes")
JOptionPane.showMessageDialog(null, outputStr1, …Run Code Online (Sandbox Code Playgroud)