我對Java很新。這段代碼有問題。試圖找到支付一定金額所需的最少數量的硬幣(例如398美分)。意外的類型
我試圖在第20,25,30,35,40,45和50行上減去後得到一個錯誤unexpected type. Required: variable. found: Value.
。我想減去一個值。我想我必須使用一種方法,但我不確定如何。任何幫助將非常感激。
public class MakingChange {
public static void main(String[] args) {
int a = 398;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int j;
int k;
int i;
int l;
int m;
int n;
int o;
if (a > 0) {
if (a >= 200) {
i = (int) a/200;
a - i * 200 = b;
} else {
a = b;
}
if (b >= 100) {
j = (int) a/100;
b - j * 100 = c;
} else {
b = c;
}
if (c >= 25) {
k = (int) c/25;
c - k * 25 = d;
} else {
c = d;
}
if (d >= 100) {
l = (int) d/100;
b - l * 100 = c;
} else {
d = e;
}
if (e >= 10) {
m = (int) e/10;
e - m * 10 = f;
} else {
e = f;
}
if (f >= 5) {
n = (int) f/5;
f - n * 5 = g;
} else {
f = g;
}
if (g >= 1) {
o = (int) g/1;
g - o = h;
} else {
g = h;
}
System.out.println(i + j + k + l + m + n + o);
}
}
}
什麼都像一個'那些表達 - 我* 200 = B;'? – Tiny