• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

work with two arrays

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone i have a requirement in which two different arrays will be there for example

int array1[]={3,5,2};
String array2[] = {"+","-"};

here my requirement is that values from first array should be calculated using the operators from the second array.
To be clear

3+5-2

and the result value 6 should be achieved...
this is a core java requirement.
If my english is not good, please don't mind.

 
Marshal
Posts: 79183
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Draw a diagram on paper of how you would do that sort of thing. Then you can work out the logic, and the code will follow easily.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is an example:

here my requirement is that values from first array should be calculated using the operators from the second array.
To be clear

3+5-2


While examples are good and can HELP clarify, they don't explain what needs to be done. What happens if there are more than two operators in the second array? What happens if you don't have enough digits in the first? Do you follow proper order of operations, or do you execute each operation as you hit it? And so on.

The idea behind programming is that you come up with detailed instructions - pretend you are trying to explain to a 10 year old child how to do what you need done. And always, explain it in English (or whatever natural language you choose) without using java terms.

Once you can explain what to do in all situations, then you start coding, but not before.
reply
    Bookmark Topic Watch Topic
  • New Topic