ユーザーが + または - 記号を入力する必要がある Java で Sports Betting Calculator を作成しようとしています。そのサインを読んで、if ステートメントに入ることができるようにしたいのです。文字列が認識しないので、その記号を認識する方法を知りたいと思っていました。これは私のコードです:
import java.util.Scanner;
public class MoneyLineCalc {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Sports Bet Calculator");
System.out.println();
System.out.print("Is it a (+ or -)?: ");
String x = scan.nextLine();
String +;
if (x == +){
}
}
}
「+」または「-」の代わりに文字を使用できることは理解していますが、このプログラムではそれらの記号を使用したいと考えています。ご意見ありがとうございます。