Java Beginners

Moderators: zibadian
Number of threads: 1285
Number of posts: 2739

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
conditional statements Posted by drifting on 31 Oct 2012 at 1:50 PM
i am trying to display some inputted data with grammatical correctness, but am having trouble programming this without an enormous amount of code. I want to tell it to print an 'and' before the last value in a sequence. But in a series of 8 values that are only printed if it doesn't equal 0 i can't figure out how to tell it this. whether in a single command or a clever series. please give suggestions. here's my code in case that helps...
if (twenty != 0) // the number of twenties given in change
   if (twenty == 1)
        System.out.print(twenty + " twenty dollar bill");
   else 
	System.out.print(twenty + " twenty dollar bills");
if (ten != 0 || five != 0 || one != 0 || quarter != 0 || dime != 0 || nickel != 0 || penny != 0)// if these aren't zero then it's a sequence that requires a comma
System.out.print(", "); // what if only one variable follows? i do i tell it to instead print an 'and'? 





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.