Я пишу программу, которая определит, является ли двойной литерал 4 символа, и выведет его на экран.Я считаю, что сделал ту часть, где я проверю, есть ли ровно 4 символа.Я застрял на том, как проверить, если +, - или.это первый персонаж.С моим str.charAt(0) == "+" || "-" || "."
я получаю сообщение о несовместимом операнде.
public class Program4 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
String str;
System.out.println("Please enter a valid (4 character) double literal consisting of these numbers and symbols: '+', '-', '.', (decimal point), and '0' through '9'");
str = stdIn.nextLine();
int length = str.length();
// the next if statement will determine if there are exactly 4 characters \\
if ( length == 4 ) {
// the next if statement checks for a +, -, or . (decimal) in the first character \\
if ( str.charAt(0) == "+" || "-" || ".") {
}
}
else {
System.out.println ("Please restart the program and enter in a valid 4 character double literal.");
}
}
}