Is there a way to create a certain number of double variables based on user input. For example a user has three cars so when asked by the software how many vehicles he has and he enters the number 3 my software will create 3 double variables named car01, car02, car03 for example. I've been googling this and can't seem to find a way to do it without just adding a bunch of variables that will not be used. Thanks if anyone can help.

Recommended Answers

All 3 Replies

No, you can't create variables like car01 at runtime. You can use a Map(like HashMap) and save data in it using a key = "car01" with any value you want.

No, you can't create variables like car01 at runtime. You can use a Map(like HashMap) and save data in it using a key = "car01" with any value you want.

Aww man that would have saved a lot of work lol.

... or simply use an array
double[] car = new double[3]
car[0] = ...
car[1] = ... etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.