user enter data to different arrays

Posted by user2900469 on Stack Overflow See other posts from Stack Overflow or by user2900469
Published on 2013-11-02T21:51:26Z Indexed on 2013/11/02 21:53 UTC
Read the original article Hit count: 208

Filed under:
|

This is fragment of my code (arrays as you can see):

    double[] Price;
    String[] names;
    int[] Quantity;


    Price = new double[5];
    names = new String[5];
    Quantity = new int[5];


    Price[1] = 3.10;
    Price[2] = 7.80;
    Price[3] = 0.20;

    names[1] = "Ballpen";
    names[2] = "Notebook";
    names[3] = "Envelope";

    Quantity[1] = 20;
    Quantity[2] = 5;
    Quantity[3] = 140;

I enter data to arrays by myself in this case. Now i want to change my code so that my program asks user for names, price and quantity (using the Scanner class). After user enter data, program keep this in three different arrays. I dont know how to transfer data from user to arrays. I would be grateful for some example code or any help.

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays