0
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]);
            }
    }

How do you continue the loop? and i need to keep it going until i press -1 to stop? i need help fuiguring out this part of the statement please state your possible answers and reason why my loop is not continous and how i can make it keep gpoing and what staement i can use to stop it

2 Answers2

0

do while is the statement you are looking for

https://www.google.ca/search?q=do+while&rlz=1C1SVEE_enES423ES423&aq=f&oq=do+while&aqs=chrome.0.57j0l3j62l2.1261j0&sourceid=chrome&ie=UTF-8

Delcasda
  • 371
  • 4
  • 13
  • check out the updated code with do while there. but the problem 'continue loop until i press -1' is still not working. any suggestions? –  May 01 '13 at 15:02
  • looks like it is not so easy to compare float numbers: http://stackoverflow.com/questions/10334688/how-dangerous-is-it-to-compare-floating-point-values – Delcasda May 01 '13 at 15:25
0

Price is declared as a float and you're comparing it to an int. Try:

if((int)price == 1)

or

if(price == 1.0f)
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85