import java.util.*; //for %d%n
import java.text.*; //for DecimalFormat
public 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"
}
}
UYOU
MM们
慕森王
相关分类