Recursion - i want to print 1, 2, 3, 4, 5 and not 1, 2, 3, 4, 5, how to do?

I'm a new to recursion. Can anyone tell me how to changes the method writeNums(int i) so it prints 1, 2, 3, 4, 5 and not 1, 2, 3, 4, 5, ?
Thanks.
public class Ex2writeNums
     public static void main(String[] args)
          writeNums(5);
     private static void writeNums(int i)
          if(i<0)
               throw new IllegalArgumentException("negative number");
          else if(i==0)
               //base case
               System.out.println();
          else
               // recursive case
               writeNums(i-1);
               System.out.print(i+", ");     
}

baudits wrote:
my code must be generic so i can use it for i=10 etc. So I can not write code like this:
     if(i != 5)System.out.print(i+", ");
else System.out.println(i);
Just add a second argument, limit, which specifies how high you must count. Your code becomes
     if(i != limit)System.out.print(i+", ");
        else System.out.println(i);There are many ways to do this. You now have at least three. Pick one.
{?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • So I need to buy a TV series on my family's account, and we want it just to charge the credit card and not the money from an iTunes Card that's already on the account. Is there any way to do this?

    So I need to buy a TV series on my family's account, and we want it just to charge the credit card and not the money from an iTunes Card that's already on the account. Is there any way to do this?

    I am pretty sure it will always use the credit card unless payment method is set to none.
    That has been my experience anyway.
    They already have the money from the gift card so would rather collect from your credit card.

  • I want to add a photo as an attachment and NOT have it pictured in the body of the email.

    I want to add a photo as an attachment and NOT have it pictured in the body of the email.
    When I click on the paper clip to attach, it always is pictured in the email.

    https://discussions.apple.com/message/16802006#16802006

  • How may I print out a picture from paper and not the photo tray?

    How may I print out a picture from paper and not the photo tray?

    From paper?  Do you have a digital image of it on your iPhone?
    "Photo tray"?  What do you mean here?  The iPhone does not have a photo tray.  Printers have trays.

  • I have Iphone 5 and mac pro, and i want to transfer pics through idrop. but my iphone not detect the mac pro. How i can turn the idrop on my computer?

    I have Iphone 5 and mac pro, and i want to transfer pics through idrop. but my iphone not detect the mac pro. How i can turn the idrop on my computer?

    The Mac Pro - the desktop computer - does not support Airdrop, if that's what you mean.
    Matt

  • If I print an email after it's sent, it prints out Subj, from,date,to and text info. I want to print all this info before I send, not just the text. How?

    If I address and compose an email and try to print it before I send it, it only prints the text, not the "Subject," "From, Date," and "To" lines in the email. After I send it, if I go into the sent register and print the same e-mail it prints out all these lines along with the text.
    I want to print the email before I send it and have the print-out contain all these lines along with the text. How do I set Thunderbird to do this all the time?

    You will get the details you want if you print from the draft folder.

  • I don't feel like buying any more printers. I told my daughter to attach the document she wanted to print to an email to me and I would see if I could print it. No problem. Will this always be true?

    Sorry. That should have been a heading and not the whole question. I am trying to figure out the question of iPad printing. If there was such a thing as a great little portable iPad printer maybe I would give my daughter one some day. But the printer I am using is working for me because I installed it as a network printer on my  wired network. It does have WiFi capabilities but it does not have the 'Air' thing.  It's an HP Officejet 4500 etc etc...My question is: will printing anything from her iPad always be as easy as she attaching a document to an email and mailing to herself on Yahoo which she can retrieve on any of 3 PCs in this house? I hope so - my computer budget is blown...

    iOS AirPrint Printers  http://support.apple.com/kb/HT4356http://support.apple.com/kb/HT4356
    How to Print from Your iPad: Summary of Printer and Printing Options
    http://ipadacademy.com/2012/03/how-to-print-from-your-ipad-summary-of-printer-an d-printing-optionshttp://ipadacademy.com/2012/03/how-to-print-from-your-ipad-summary-of-printer-an d-printing-options
    How to Print from Your iPad
    http://www.dummies.com/how-to/content/how-to-print-from-your-ipad.htmlhttp://www.dummies.com/how-to/content/how-to-print-from-your-ipad.html
    How do you print directly from the iPad
    http://www.everymac.com/systems/apple/ipad/ipad-faq/how-to-print-documents-direc tly-from-ipad.htmlhttp://www.everymac.com/systems/apple/ipad/ipad-faq/how-to-print-documents-direc tly-from-ipad.html
    Print from iPad / iPhone without AirPrint
    http://ipadhelp.com/ipad-help/print-from-ipad-iphone-without-airprint/http://ipadhelp.com/ipad-help/print-from-ipad-iphone-without-airprint/
    How to Enable AirPrint on a Mac and Use Any Printer
    http://ipadhelp.com/ipad-help/how-to-use-airprint-with-any-printer/http://ipadhelp.com/ipad-help/how-to-use-airprint-with-any-printer/
    iPad Power: How to Print
    http://www.macworld.com/article/1160312/ipad_printing.htmlhttp://www.macworld.com/article/1160312/ipad_printing.html
    Check out these print apps for the iPad.
    Print Utility for iPad  ($3.99) http://itunes.apple.com/us/app/print-utility-for-ipad/id422858586?mt=8http://itunes.apple.com/us/app/print-utility-for-ipad/id422858586?mt=8
    Print Agent Pro for iPad ($5.99) http://itunes.apple.com/us/app/print-agent-pro-for-ipad/id421782942?mt=8http://itunes.apple.com/us/app/print-agent-pro-for-ipad/id421782942?mt=8   Print Agent Pro can print to many non-AirPrint and non-wireless printers on your network, even if they are only connected to a Mac or PC via USB.
    FingerPrint turns any printer into an AirPrint printer
    http://reviews.cnet.com/8301-19512_7-57368414-233/fingerprint-turns-any-printer- into-an-airprint-printer/http://reviews.cnet.com/8301-19512_7-57368414-233/fingerprint-turns-any-printer- into-an-airprint-printer/
    Print (Print to ALL Printers) ($1.99)
    https://itunes.apple.com/us/app/print-print-to-all-printers/id299423224?mt=8https://itunes.apple.com/us/app/print-print-to-all-printers/id299423224?mt=8
     Cheers, Tom

  • Prints in PS CC incorrect format and not borderless - please help?

    Hi
    I am new to printing and thought I would get the basics before I upgrade the printer. I just can't get my prints to reflect correctly on paper, please help - I will explain by way of pictures
    The first image is what I want to print but borderless. The only difference between the other two prints is the layout button - Landscape (second Print) and Portrait (Third Print) from the screenshots attached seems to be back to front also in the preview? (I did not print the first print) For the second and third prints I sized the images as per the screenshot and I printed on A3 Paper.
    My questions are:
    1. Why is my preview wrong - landscape shows as portrait orientation in the preview window and vice versa?
    2. Why can't I print borderless - is this a function of the printer not being able to do so or am I doing something wrong?
    3. Why can't I get the full photo to print with these settings with/without a border?
    Your help will be appreciated.
    I am using Photoshop CC 2014 and HP Deskjet 7610, A3 paper, Mac Book Pro and the last bit of my patience.
    Maddie

    Borderless is a function of the printer and driver, not the application.
    It sounds like your printer driver also overrode the landscape vs. portrait setting somehow.
    Double check all your settings in the printer driver dialog.

  • I want to set up Skype on my iPad and sync addresses with my iMac.  How do i do this?

    I have just purchased an ipad.  i want to set up Skype on my iPad and then sync contact info with my iMac.  How do i do this?

    If you sign in with the same Skype username as you do on the iMac, your contacts should be there.

  • Hi i am new to labview. i want to extract data from a text file and display it on the front panel. how do i proceed??

    Hi i am new to labview
    I want to extract data from a text file and display it on the front panel.
    How do i proceed??
    I have attached a file for your brief idea...
    Attachments:
    extract.jpg ‏3797 KB

    RoopeshV wrote:
    Hi,
    The below code shows how to read from txt file and display in the perticular fields.
    Why have you used waveform?
    Regards,
    Roopesh
    There are so many things wrong with this VI, I'm not even sure where to start.
    Hard-coding paths that point to your user folder on the block diagram. What if somebody else tries to run it? They'll get an error. What if somebody tries to run this on Windows 7? They'll get an error. What if somebody tries to run this on a Mac or Linux? They'll get an error.
    Not using Read From Spreadsheet File.
    Use of local variables to populate an array.
    Cannot insert values into an empty array.
    What if there's a line missing from the text file? Now your data will not line up. Your case structure does handle this.
    Also, how does this answer the poster's question?

  • I want firefox to remember my email address only and not password

    I only want firefox to remember email address and not password when I want to login to gmail

    You can disable the Firefox Password Manager and use form autocomplete to remember the name.
    * Tools > Options > Security: Passwords: [ ] "Remember passwords for sites"
    * Tools > Options > Privacy > History: [X] "Remember search and form history"
    * [[Remembering passwords]]
    * [[Form autocomplete]]

  • EPrint prints photo using my main tray and not the photo tray

    Hello,
    Thanks for reviewing my question.  I just bought the HP Photosmart C410 printer and setup the ePrint.  When I print a photo from my iPhone it prints on the photo on the 8.5 x 11 paper instead of the photo tray.  What gives?
    Many Thanks
    Peter

    Hey PDonstant,
    1. You can go into the setup menu on the printer and go into preferences. In preferences you can go to Device Printer Tray Select and choose prompt for tray. This will give you the option to print to photo paper or Legal size. 
    2. You can try downloading the HP ePrint Home & Biz app and printing from there. You have the option to select the paper size and type from the app.
    Although I am an HP employee, I am speaking for myself and not for HP.
    If I have resolved your issue, feel free to provide Kudos and make sure you mark this thread as solution provided.

  • I have an iPad 3 and want to print to my hp wireless 8180 and it can't find it. what should i do?, I have an iPad 3 and want to print to my hp wireless 8180 and it can't find it. what should i do?

    I need help to print to my ipad3. I have a wireless HP 8180 and when I try to set it up the ipad can't find the printer.Can anyone help me set this up correct?

    Try the HP print App; http://itunes.apple.com/app/hp-eprint/id299531647?alreadyRedirected=1&mt=8
    You can also try this App; http://itunes.apple.com/app/hp-printer-control/id469284907?alreadyRedirected=1&m t=8

  • Hello Community...Macbook w 10.6.8 and I need printing help. Using three canon photo printers of same model and need them to print individually. They are older and NOT network-able. Currently using another Mac to print to 2nd printer. 3 is idle.

    Is there software available where all I have to do is hit print and any of the 4x6 printers will print? Once I get this issue settled, I'll get a second larger format. I have to get this rectified because of time and ease. As mentioned, I have a second mac that I share screens with so my assistant can find pics for customers while I'm shooting. So, I can print through that mac to the printer. (ie....print to canon@##%#@Mac 2) I don't want to bring a third computer just to print to three of the same model printer. (That's what I've been doing) BTW....I totally know there are faster dye-sub printers out there but I'm about 4 more events from purchasing one...($$$) Some print under 10 seconds. I would appreciate any answers out there. Thank you.

    I don't have that printer and I'm not on Mac, so someone else has to step in there. Generally a green/magenta cast indicates none/double printer color management. But then I don't know what you mean by "slight".
    The Spyders aren't the most consistent and reliable calibrators out there. I had a Spyder 3 sensor that I just threw away because it gave a distinct red cast (I have several other calibrators, so there was no doubt). Another potential problem is that with most calibrators you can only adjust the white point along the blue/yellow Kelvin scale, but not on the green/magenta scale. This is often necessary to get a good white point color. In this case you need to use the monitor's OSD controls, and if possible the "pre-calibration" function in the calibrator to measure and monitor it - if that function exists. And I don't know if this is possible with an iMac.
    This is basically a question of getting the white point right, both on the blue/yellow and the green/magenta axis (and luminance of course). The goal is to get a visual match to paper white on screen. With the white point properly set, neutral color balance relates to that, and the rest more or less follows by itself. (In addition you should set the proper black point/contrast for full control, but that's not the issue here).

  • HT4623 I want to install an app that requires iOS5 and my iphone is 4.2.6 How do I Update my software for my iphone 4?

    I want to install an app that requires iOS 5 update. How do I update the software on my phone when I do not have the icon in settings for update software? Please help!

    Connect your iPhone to iTunes, and find Software Update in the main interface pane. It should prompt you to install iOS 5.1.1.

Maybe you are looking for

  • Adding images to a ListBox in Applet

    Hi, I wanted to add images to an Listbox as that of an Yahoo IM or AOL (IM) has. Do any one have any idea? Here is my code for Java, Please tell me where should I have to correct my code so that I can achieve such a thing. or if you do have time, ple

  • Problem in loading an external file with unicode name

    Hi, I am working on a project which involves loading of an external file with unicode name for ex: "插入音乐.mp3 ,插入音乐.jpg". These unicode files are loaded successfully when I play/publish the movie with flash player alone. But when the movie is embedded

  • Lenovo T61 (Product 6458-W2R): explorer.exe hangs after logon - WinXP SP2

    +++ english below +++ [german/deutsch] Wir setzen in unserem Unternehmen mehrere ThinkPad T61 ein.  Bei einigen dieser ThinkPad T61 (und nur beim ThinkPad T61!) haben wir inzwischen ein seltsames Phänomen, welches im Laufe der letzten 1-2 Monate auft

  • My mac book air fan is staying on, how can I get it back to normal?

    I cna hear the processor or fan in my Mac Book Air, and it won't stop. Has anyone had a similar problem? Does anyone have any ideas about how I might resolve this issue? Thanks for your help!

  • Error 4310 Windows 8 Cannot burn playlist too cd.

    I have Windows 8, i just downloaded itunes 2 days ago, i checked for update there was none, i slowed the download speed to 1x, still did not work, used a different cd, still did not work. ANY help at all? Laptop stats, Intel i7 duel core proccessor,