Ich erhalte die Fehlermeldung:Bad Operandentypen für binäre Operator ‚*‘
error: bad operand types for binary operator '*'
if ((monthD * dayD).equals("yearD"))
^
first type: String
second type: String
Der Punkt des Codes ist zu sehen, ob der Monat und das Datum des Jahres gleich, wenn multipliziert.
Hier ist mein Code:
// Month
String monthD;
System.out.print("What is the month? (For example, August would inserted as '08') ");
monthD = userInput.nextLine();
// Day
String dayD;
System.out.print("What is the day? (For example, the 10th of the month is inserted as '10') ");
dayD = userInput.nextLine();
// Year
String yearD;
System.out.print("What is the year? (For example, 1998 is inserted as '98') ");
yearD = userInput.nextLine();
// Is this date magic?
if ((monthD * dayD).equals("yearD"))
{
System.out.print("This date is magic!");
}
else
{
System.out.print("This date is not magic!");
}
Warum Sie Ihre Eingabe als String lesen, wenn Sie int wollen? – Tom
Ihre Logik ist auch falsch, zuerst überprüfen, was Sie vergleichen möchten. – Omore
Ich versuchte Int und Double auch und es hat nicht funktioniert, das ist nur die letzte Option, die ich ausprobiert habe. Was soll ich sonst machen? – MadCodez