I am stuck on an issue described below
Suppose we have a string like 42932-5, which has 6 numbers
I want to calculate the total sum as
4*6+2*5+9*4+3*3+2*2
How do we do this in Java?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I can’t say this efficent, I’m sure there’s a better way to go about it, but hay, it was fun 😛
The first thing you need to do is discard the parts of the
Stringyou don’t needNow, you could use a
StringBuilderinstead of aList, but this was what came off my head.Next, you need to sum them
And I ended up with something like