1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy
Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Monday's Programming Question

Monday December 15, 2008

Today's programming question is all about converting Strings to numbers. The Double and Integer wrapper objects both have methods that are capable of converting a String value. The Java program to write this week will need to employ those methods.

Write a program that inputs a String from a user. The String will be a series of numbers each separated by a space (e.g., "11 2 36.4 4 8.9 7.6 3 256"). Convert the String into the series of numbers that it represents and add them all together. Finally display the result to the user. To make things a little more interesting allow for the String to include octal and hexadecimal literals (e.g., "11 2 0xEF 36.4 4 8.9 0647 7.6 3 256").

To test the program use the following String: "56.7 0.8 345 0xEFF 8.99 126 0647 73 5.67".

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Discuss
Community Forum
Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java

©2009 About.com, a part of The New York Times Company.

All rights reserved.