【发布时间】:2018-02-11 10:47:44
【问题描述】:
只是想在我的书中做一个任务,但我不明白为什么这是错误的。应该说负数不是正数,正数不是布尔值的负数。 这是我的代码:
import javax.swing.JOptionPane;
public class Zahlentest {
public static void main(String[] args) {
String eingabe;
char Zahl;
boolean istVokal;
eingabe = JOptionPane.showInputDialog("Geben Sie eine Zahl ein: ");
if (Zahl == "- && Zahl") {
istVokal = false;
} else {
istVokal = true;
}
if (istVokal == true) {
JOptionPane.showMessageDialog(null, "Die Zahl ist nicht negativ!");
} else {
JOptionPane.showMessageDialog(null, "Die Zahl ist negativ!");
}
}
}
我不知道我做错了什么......请帮助。 这是错误代码:
Zahlentest.java:10: error: bad operand types for binary operator '=='
if (Zahl == "- && Zahl") {
^
first type: char
second type: String
1 error
【问题讨论】:
-
注意
Zahl应该是小写的,因为它是一个变量;如果您担心zahl是消极的还是积极的,那么istVokal是没有意义的。 -
好吧,错误很清楚地告诉您
char == String无效,尽管您还不清楚您希望该行做什么。您还没有将该变量分配给任何东西。
标签: java cmd binary operator-keyword operand