私はプログラムを書きました..ユーザーはフォーマット(バーコード、価格:アイテムの数)で文字列を入力する必要があり、バーコードの合計を計算します
私のコードは
import java.util.*;
public class hanoofee2 {
public static void main (String args[]) {
Scanner input=new Scanner (System.in);
System.out.println("Enter a string with format (Barcode,price:number of item) ");
String ent = input.nextLine();
String barcode = ent.substring(0,(ent.indexOf(",")));
String price = ent.substring((ent.indexOf(","))+1,(ent.indexOf(":")));
String number = ent.substring(ent.indexOf(":")+1,(ent.length()));
double price2 = Double.parseDouble(price);
int number2 = Integer.parseInt(number);
double total = price2 * number2;
String m = "";
if(barcode == "11A") {
m ="green pen";
} else if(barcode == "22B") {
m ="printer";
} else if(barcode == "44C") {
m ="Memory card";
} else if(barcode == "44D") {
m ="Cook book";
}
System.out.printf("The total price of%2s "+" is:%.2f ", m ,total);
}
}
すべて問題ありませんが、実行を押しても「m」の値が表示されません
Enter a string with format (Barcode,price:number of item)
22B,222:30
The total price of is:6660.00
----jGRASP: operation complete.
何が問題ですか ?!