Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Append digit to end of variable

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 09-08-2008, 01:16 AM PM User | #1 Crazydog Regular Coder   Join Date: May 2005 Posts: 224 Thanks: 1 Thanked 0 Times in 0 Posts Append digit to end of variable Hey everyone. I have this assignment for school where I have to create a very simple calculator program. No GUI, not even command line inputs. It's all being run inside the program with preset commands. Here's the problem: I can't figure out how to append a digit to the end of a variable. The calculator must work like this: (it is java, not php. The highlighting makes it easier to read) PHP Code: ``` //press "5"calc.digit(5);//press "3"calc.digit(3);//Should display: "53"System.out.println(calc.display());  ``` I can't for the life of me figure out how to set 5 to a variable, and then add 3 to the end of that variable. Can anyone help? Many thanks. Note: the digit method requires the number to be an int Last edited by Crazydog; 09-08-2008 at 01:20 AM..
 09-08-2008, 04:06 AM PM User | #2 icm9768 New Coder   Join Date: Jun 2005 Posts: 32 Thanks: 0 Thanked 2 Times in 2 Posts A fairly straight forward approach would be to multiply your existing number by 10 and then add the new digit. So in your example below the user enters 5. Since your initial number would be zero the operation would be ( 0 * 10 ) + 5. Now your calculator input is five. Then the user enters 3 so the next operation would be ( 5 * 10 ) + 3. Now the user input is 53 and so on and so forth.
 Users who have thanked icm9768 for this post: Crazydog (09-08-2008)
 09-08-2008, 04:30 AM PM User | #3 Crazydog Regular Coder   Join Date: May 2005 Posts: 224 Thanks: 1 Thanked 0 Times in 0 Posts Thanks. I was thinking about that in the first place, but didn't put too much thought into it, since I assumed there would be a more practical way.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 03:32 AM.