任何人都可以幫助我嗎?我們的老師說他不想在我們的程序中使用數組列表。只有數組,for循環,並且只做。該程序是一個購買程序(添加項目,記錄交易)。這是我想了解的第一步。購買Java part 2
在這個程序中,我想要正確顯示項目代碼和descip。例如code = 123和descrip =是的。輸出顯示,Item code = 123, Item descrpition = yeah.
但是,一旦我說是,我把另一個,例如代碼= 456和desription =哦。輸出Item code = 123456, Item description = yeah.oh.
import java.util.Scanner;
public class Apps {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
String code = "", des = "", ans;
String[] b = new String[1];
String[] aw = new String[1];
int x;
do {
System.out.print("Item code:");
code += "" + a.next();
System.out.print("des:");
des += "" + a.next();
System.out.println("yes or no:");
ans = a.next();
}
while (ans.equals("yes"));
for (x = 0; x < 1; x++) {
b[x] = code;
aw[x] = des;
System.out.println("Item code:" + b[x]);
System.out.println("Item description:" + aw[x]);
}
}
}
此代碼可能導致無限循環。 – 2013-10-10 13:04:10
請格式化您的代碼。 –
@nikpon這就是我的教練想要的。無限無固定價值。 – Raymond