我正在構建一個計算器來計算醫用大麻藥房的價格。所有銷售均需繳納 16% 的稅,以及某些重量的價格優惠。我的目標是在考慮到稅收和休息時間的情況下,為客戶找到一個以最優惠價格出售的重量。我只是試圖獲得雙打串列的最高值,與斷點陣列進行比較,看看它們是否滿足斷點的特定閾值。從字面上看,我似乎無法獲得weightList陣列中的最大雙精度值。這是我的代碼。我的雙打gramPrice、eighthPrice等是給定斷點處的價格/克。的gramWeight,eighthWeight,等都是產品的計算在那個斷點收到的重量。有點草率的術語我猜,但我怎樣才能找到我的雙陣列的最大值?
import java.util.Scanner;
import java.text.DecimalFormat;
public class main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("##.##");
int desiredPrice = 0 , pricePoint = 0;
int fivePerGram[] = {5, 15, 25, 50, 100};
int eightPerGram[] = {8, 25, 45, 90, 160};
double weightFormat[] = {1, 3.5, 7, 14, 28};
System.out.print("Enter Desired Amount OTD: ");
if(reader.hasNextInt() == true) {
desiredPrice = reader.nextInt();
}
System.out.print("Enter Price Point (3, 5, 8, 10, 12): " );
if(reader.hasNextInt() == true) {
pricePoint = reader.nextInt();
}
if(pricePoint == 8) {
double gramPrice = (eightPerGram[0]/1)*1.16;gramPrice = Double.parseDouble(df.format(gramPrice));
double eighthPrice = (eightPerGram[1]/3.5)*1.16;eighthPrice = Double.parseDouble(df.format(eighthPrice));
double quarterPrice = (eightPerGram[2]/7)*1.16;quarterPrice = Double.parseDouble(df.format(quarterPrice));
double halfPrice = (eightPerGram[3]/14)*1.16;halfPrice = Double.parseDouble(df.format(halfPrice));
double ouncePrice = (eightPerGram[4]/28)*1.16;ouncePrice = Double.parseDouble(df.format(ouncePrice));
double gramWeight = desiredPrice/gramPrice;gramWeight = Double.parseDouble(df.format(gramWeight));
double eighthWeight = desiredPrice/eighthPrice;eighthWeight = Double.parseDouble(df.format(eighthWeight));
double quarterWeight = desiredPrice/quarterPrice;quarterWeight = Double.parseDouble(df.format(quarterWeight));
double halfWeight = desiredPrice/halfPrice;halfWeight = Double.parseDouble(df.format(halfWeight));
double ounceWeight = desiredPrice/ouncePrice;ounceWeight = Double.parseDouble(df.format(ounceWeight));
double weightList[] = {gramWeight, eighthWeight, quarterWeight, halfWeight, ounceWeight};
}
}
}
uj5u.com熱心網友回復:
請注意,我很確定我明白你要做什么。如果您想要weightList陣列中的最大值,只需執行以下操作。
使用標準 Java 8
final double maxWeight = Arrays.stream(weightList).max().getAsDouble();
與其他圖書館
Apache Commons Lang3 的 NumberUtils
final double maxWeight = NumberUtils.max(weightList);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/333891.html
下一篇:這是在c中按頻率排序的陣列
