import java.util.*; //for %d%nimport java.text.*; //for DecimalFormatpublic class Favorite {public static void main(String[] arguments) {String itemName = "Golden Beans";float offerPrice = 314;float sellPrice = 321;float value = (sellPrice - offerPrice);float cashStack = 500_000;float maxAmount = (cashStack / offerPrice);float percentageProfit = ((value / offerPrice) * 100);System.out.println("Approx. Offer Price is " + "\t" + offerPrice);System.out.println("Approx. Sell Price is " + "\t" + sellPrice);System.out.println("The potential profit margin is " + value);System.out.printf("With a cash stack of " + cashStack + " we can buy " + "%.0f%n", maxAmount);//why can't I add + itemName; it gives me a compile error when using printf. I can add as much text etc before but not after using + "%.0f%n"System.out.printf("The profit margin of " + itemName + " as a percentage is "+ "%.3f%n", percentageProfit);//why can't I add text here; it gives me a compile error when using printf. I can add as much text etc before but not after using + "%.0f%n" } }
BASIC,在調用 %d%n 后不能輸出任何其他字符串嗎?
慕的地8271018
2021-08-19 18:32:51