Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How correctly parse string value in JAVA from text in sum?

i have a problem with one task in Java. I have text file with these numbers –

input : 000000004599
000000001000

And the result should be –
output: 45.99
10.00
sum of two varriables – 5599 (yes,without "dot")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I only have guesses that it is necessary to remove numbers from the beginning through the array.
Example :
if (arr[i] = 0 && arr[i + 1] = 0) {

}

I’m sure there is another logical solution

>Solution :

You can simply use Integer.parseInt.

Integer.parseInt("000000004599") + Integer.parseInt("000000001000"); // 5599
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading