
Java Programming in 60 seconds. Here I explain how to convert numbers such as Doubles and Integers into strings and back again. You may need to do this in your Java programs when you take input via a form, from the system prompt or from a file. If you need to understand numeric data types such as double and int and how they work with wrapper classes such as Double and Integer, see my other video: Primitive data types and Java class wrappers http://youtu.be/FogMzP5oU4o When someone enters text in a text field on a form or at the system prompt, it has the string data type -- that is, it is treated as a sequences of characters '1' '0' '0', for example, rather than the number 100. To do calculations you must convert the strings to numbers. There are several ways of doing that. One way is to use the valueOf method provided by a number class such as Double. That takes a string and returns its numeric equivalent. To convert a number back to a string, use the number class's toString method. That's what I do when I need to display the result of a calculation as a string in my calculator. For more hints and tips be sure to subscribe to the Bitwise Courses YouTube channel: http://www.youtube.com/BitwiseCourses For in-depth programming tutorials, see the Bitwise Courses web site: http://www.bitwisecourses.com/ The music in this video was composed by Nic Croll. For more of Nic's music, visit: http://www.nicolascroll.com/
Java Programming in 60 seconds: Converting Numbers and Strings, programming a Calculator - YouTube |
1 Likes | 1 Dislikes |
1,102 views views | 2,611 followers |
Education | Upload TimePublished on 21 Apr 2014 |
Không có nhận xét nào:
Đăng nhận xét