【发布时间】:2018-02-21 09:37:43
【问题描述】:
我开始学习 java,但我的一个程序遇到了问题。 我试图根据用户输入的天线类型来获得天线的电感。 问题是我有对话框并且我输入了输入,但之后我的代码停止并且它没有执行循环。我一直在浏览网络,但找不到 if 语句不接受我的输入的原因。 这是我的代码的一部分:
import javax.swing.*;
//import javax.swing.JOptionPane;
public class Antenna_Inductance {
public static void main(String[] args) {
// first we will define all the variable use of the problem set
// for the lime antenna
double M;
int N1;
int N2;
double R1;
double R2;
// now we can start to programmed the main code
String Type= JOptionPane.showInputDialog("Type of Antenna");
// this is where the code stop and i don't know why
if (Type == "line") {
String input_rmin= JOptionPane.showInputDialog("Enter minimum distance for r");
double rmin = Double.parseDouble(input_rmin);
String input_rmax= JOptionPane.showInputDialog("Enter maximum distance for r");
double rmax = Double.parseDouble(input_rmax);
I = 0.01;
for (r=rmin; r==rmax ;r+=0.05) {
B_line = (mu*I)/(2*pi*r);
System.out.println("Inductance for line antenna =" + B_line);
}
所以,我真的可以在这方面使用一些帮助。谢谢你,祝你有美好的一天
【问题讨论】:
-
JOptionPane 用于 JFrame 窗口。字符串比较:
if (Type.equals("line")) {。查看演示。
标签: java string swing if-statement joptionpane