final static int arrayLength = 1000; //maximum array size
static float[] productPrice = new float[arrayLength]; //stores the prices of products
static String[] productName = new String[arrayLength]; //stores the names of products
public static void main(String[] args) {
boolean quit = false;
do {
System.out.print("enter product: ");
String product = keyboard.nextLine();;
for(int i=0; i<productName.length; i++)
productName[i] = product;
System.out.print("enter price: ");
float price = keyboard.nextFloat();
for(int i=0; i<productPrice.length; i++)
productPrice[i] = price;
if(price == -1)
quit = true;
} while(!quit);
for(int i=0; i<productPrice.length; i++)
if(productPrice[i] > productPrice[i+1]) {
float temp = productPrice[i+1];
productPrice[i+1] = productPrice[i];
productPrice[i] = temp;
System.out.println("Product: " + productName[i] + "\nPrice: " + productPrice[i]);
}
}
你如何继续循环?我需要继续运行直到我按 -1 停止?我需要帮助来完成声明的这一部分请说明您可能的答案和为什么我的循环不连续的原因以及我如何使它保持 gpoing 以及我可以使用什么来阻止它