Can Anyone Write a Program that does this?

Once again , I know it's simple but I unfortunatly can't accomplish this task if anyone can write this program for me with the use of simple recursive arguements I would appreciate it..
pre: n greater than or equal to 0
post: return true if n is prime and false otherwise
thats the problem

I scrapped working on that one , heres what im doing now..public class plus251
We are to Recursively add well you can read the pre and post conditions, now im basically supposed to follow this same setup which I wrote out , but now im too multiply by adding and I cant figure out the recursive part I know that the base case is if a == 1 return b , but its the else which I have no clue how to write..
public static void main(String[]args)
     /* pre: a and b are positive integers
     post: outputs a + b by adding 1 to b, a times
     int a, b;
     System.out.println("enter an integer");
a = Console.readInt();
System.out.println("enter an integer");
b = Console.readInt();
     System.out.println("a+b = "+ plus(a,b));
public static int plus(int a, int b)
     /* pre: a and b are positive ints
     post: returns a + b
     if (a==0)
     return(b); /* this will add the accumulated
ones to b to get the total */
     else
     return(1+plus(a-1, b)); /*this returns 1 until a
becomes 0 */
     a is 0 ---- return b
     plus(b, k) ---- returns mathplus(b, k)
     plus(b, k+1) --- returns mathplus(b, k+1)
plus(b,k+1) ---- returns 1+ plus(b, k)
|
     |          1+ mathplus(b, k)
|
     ------------------ mathplus(b, k+1)

Similar Messages

  • I can't find preferences for the notes app. and every once in awhile some of my notes just disappear at start up, I see the name and then it refreshes and they are gone, very annoying. Can anyone tell me why it does this and how to stop it? thanks

    I can't find preferences for the notes app. and every once in awhile some of my notes just disappear at start up, I see the name and then it refreshes and they are gone, very annoying. Can anyone tell me why it does this and how to stop it? thanks

    Hi again, I am on an iMac using OSX 10.7.5, I"ve taken screenshots to show you I think my settings are correct

  • How can I write a program that compiles without warnings?

    I tried the following with the 1.5 beta-compiler (build 28; I think):
    class Y {
         public static final class Pair<X,Y> {
           private X fst;
           private Y snd;
           public Pair(X fst, Y snd) {this.fst=fst; this.snd=snd;}
           public X getFirst() { return fst; }
           public Y getSecond() { return snd; }
           public String toString() { return "("+fst+","+snd+")"; }
      public static void main(String... args) {
         Pair[] pairArr = new Pair[10];              // supposed to be an array of Pair<Integer,Integer>
         for (int i=0; i<pairArr.length; i++)
             pairArr[i] = new Pair<Integer,Integer>(i,i);
         for (int i=0; i<pairArr.length; i++) {
             Pair<Integer,Integer> p = pairArr; // unchecked warning
         System.out.println(p);
         Integer first = p.getFirst();
         Integer second = p.getSecond();
    // ... more stuff ...
    It turns out that I get an unchecked warning when I extract an element from the array of pairs. Okay, that's fine. How can I avoid the warning? I had expected that an explicit cast would help.
      Pair<Integer,Integer> p = (Pair<Integer,Integer> )pairArr;
    With a cast I'm telling the compiler: "I _know_ what I'm doing; please trust me." But the compiler still issues a warning.
    How can I write a warning-free program in this case? The only thing I can think of, is not using the parameterized type Pair in its parameterized form. But it's not the idea of Java Generics that I refrain from using parameterized types. What am I missing?

    It turns out that I get an unchecked warning when I
    extract an element from the array of pairs. Okay,
    that's fine. How can I avoid the warning? I had
    expected that an explicit cast would help.
    Pair<Integer,Integer> p = (Pair<Integer,Integer>
    )pairArr;
    With a cast I'm telling the compiler: "I _know_ what
    I'm doing; please trust me."  But the compiler still
    issues a warning.  Yes, but at least you were able to change the warning from "unchecked assignment" to "unchecked cast" which is a little shorter ;-)
    Seriously , since arrays of generic types are disallowed, there is probably no way to get rid of these warnings - which makes a strong point for eliminating "unchecked" warnings altogether (see the other thread "selectively suppressing compiler warnings")
    Cheerio,
    Gernot

  • Is there a program that does this

    ok i have a 20 gig 4th gen ipod and now im getting the new 60 gig video ipod..is there a program that will let me plug both of them in and transfer music directly from the 20 gig to my new 60 gig..or does anyone have any other ideas besides copying all my music to the pc and readding it to the new ipod..thanks apreciate all help

    Hi Heather
    I can't see any programme that will copy directly between two iPods. I think you'll just have to copy to your hard drive and then back onto the new iPod.
    I don't keep my music on my computer either. It doesn't take that long to copy it over and if my iPod crashes, well hey, I have the cds and it's a chance for a clear out!
    I'm on my 3rd iPod and have never had cause to be concerned about the safety of my files yet. Unfortunately on here there is a tendancy for people to lecture you on what they think you should be doing, rather than to answer the question you've asked.
    Sarah ;o)
    iBook G4 14 1GHz 640MB   Mac OS X (10.3.9)   iBook 500/iMac 333/iPods 2G20 + 4G40 + 5G60 + 1G Shuffle

  • Wallpaper program that does this....

    The mac has the option to change the desktop images ever 5 seconds as the slowest change rate but I was wondering is there a program that can make it change faster like maybe ever second or even less?
    Message was edited by: gfann18

    I'm not really doing anything of importance. I was trying to create a neat little moving wallpaper image because I don't really like static images. I get bored with them pretty quick. So I took an image of a red orb and using simple image editing tools in the previewer app, I created different color variations of the image. So when you set the desktop image to change ever 5sec to create a pulsating orb on my desk top. So Now I was thinking if I could make the image cycle faster then I could create my own simple animation or possible take a scene and make the lights turn on and off or create a seemingly flowing stream of water but in order to get the effect right I would need the image to cycle a little faster. That's what I was doing, nothing really major.

  • I want to edit a downloaded document. Can anyone recommend a program to do this. Thank you

    Hi I am new to macs. Like I said above I want to edit a downloaded document. Can anyone recommend a good programme to do this. Thanks

    there are 1000's of document formats in the world
    so it really comes down to what type you wish to edit
    if I were you then I would checkout libre office and maybe iworks

  • How can I download TV programmes from the BBC iplayer. Is there an app for ipad that does this?

    I have an ipad 2. I have BBC iplayer. The programme stops and starts as the broadband cannot cope with the streming. The solution is to download the programme from the BBC iplayer and into the ipad 2 for viewing later without all that mucking about with the streaming bit.
    Can anyone tell me if it is possible to download a programme from the BBC iplayer into an ipad 2? If there is an application that does this what is it?
    Many thanks to you all.

    There is no iPad app to do this - the BBC's television license agreement wouldn't allow it.
    There are desktop programs which will download programmes from BBC iPlayer which you can then sync to the iPad via iTunes, but technically they also operate against the terms of the iPlayer license. Google will help you find them.

  • Itunes document manager pro will not open a document with .cwk extension. It will catch the document then error message states that it cannot open document. Can anyone tell me what Im doing wrong?

    Itunes document manager pro will not open a document with .cwk extension. It will catch the document then error message states that it cannot open document. Can anyone tell me what Im doing wrong?

    Forgive my ignorance but I have never hear of iTunes Document Manager Pro. If you mean Document Manager Pro, i was able to find that. Back to your problem, have you tried opening one of those files in the iOS iWorks apps? Form the quick read that I did about this, .cwk files can be opened by Pages, Numbers or Keynote, depending on what type of document that it is and those files can be read by Document Manager Pro, after properly saving them. I don't see that you can go directly from the .cwk file in Document Manager Pro without converting them first.
    I took a very quick look at the app, so I may be a missing something about its capability.

  • Hi, I have recently updated my iMac from OS x mountain lion to OS X Mavericks. After that I can't upload any video and some files to my personal email account. Can anyone please help me to sort this problem.

    Hi,
    I have recently updated my iMac from OS x mountain lion to OS X Mavericks.
    After that I can't upload any video and some files to my personal email account.
    I have tried to send a small video clip to the sender as attachment. i have done this before
    with the same video same and same email account. This problem found just after installed the
    OS X Movericks. Can anyone please help me to sort this problem.
    Thanks.
    Roman

    Please follow these directions to delete the Mail "sandbox" folders. In OS X 10.9 there are two sandboxes, while in earlier versions there is only one.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Containers/com.apple.mail
    Right-click or control-click the highlighted line and select
    Services ▹ Reveal
    from the contextual menu.* A Finder window should open with a folder named "com.apple.mail" selected. If it does, move the selected folder — not just its contents — to the Desktop. Leave the Finder window open for now.
    Log out and log back in. Launch Mail and test. If the problem is resolved, you may have to recreate some of your Mail settings. You can then delete the folder you moved and close the Finder window. If you still have the problem, quit Mail again and put the folder back where it was, overwriting the one that may have been created in its place. Repeat with this line:
    ~/Library/Containers/com.apple.MailServiceAgent
    Caution: If you change any of the contents of the sandbox, but leave the folder itself in place, Mail may crash or not launch at all. Deleting the whole sandbox will cause it to be rebuilt automatically.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combinationcommand-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar, paste into the box that opens (command-V). You won't see what you pasted because a line break is included. Press return.

  • I'am getting an update error when am trying to upgrade to newer version (4.3.2)..the error message content shows that i tunes could not back up the i pod,because the back up was corrupt or not compatible with ipod..can anyone help me out to fix this issue

    I'am getting an update error when am trying to upgrade to newer version (4.3.2)..the error message content shows that i tunes could not back up the i pod,because the back up was corrupt or not compatible with ipod..can anyone help me out to fix this issue

    Hi,
    Try here:  http://support.apple.com/kb/HT1808. 
    Hope this helps! 
    ---likeabird---

  • I am using a MacBook Pro and am trying to print double sided copies on the HP Deskjet 3054 that came with it. Can anyone tell me how to do this?

    I am using a MacBook Pro and am trying to print double sided copies on the HP Deskjet 3054 that came with it. Can anyone tell me how to do this? I am a total MacBook nube and can use any help you may offer! Thank you so much.

    How you enable double-sided printing can depend on the applications from whick you wish to print. Example: if I print to my HP PhotoSmart  from Safari, I get this print dialog box:
    (Edit: OOPS! Note that I forgot to switch printers when i took the scene-shots, so ignore the "Brother" reference. It's should look the same for your HP.
    Note the selection labled "Safari" near the bottom. If I change that form "safari to "Layout: I get this:
    Note the option for two-sided printing appears for your selection. If I print from Word, the box is different:
    The "Copies & Pages" option can be changed to "Layout" when you click it, again allowing the selection of two-sided printing.
    If you tell us what applciaiton is vexing you, we may be able to give better-focused information.
    A

  • My Iphone 4 is changing screens without me touching it. I will be in a msg and it will jump out of that msg and into another one... can anyone please help me with what this could be?

    my Iphone 4 is changing screens without me touching it. I will be in a msg and it will jump out of that msg and into another one... can anyone please help me with what this could be?

    Try the basics from the manual.
    restart.
    reset.
    restore.
    iPhone User Guide (For iOS 4.2 and 4.3 Software)

  • I am new to mac... and there is a solid black bar on my screen, that announces what page/icon I am on, then scrolls through every screen and announces what it is.  Can anyone tell me how to remove this?? Please? Thank you

    I am new to mac... and there is a solid black bar on my screen, that announces what page/icon I am on, then scrolls through every screen and announces what it is.  Can anyone tell me how to remove this?? Please? Thank you

    You may also find these Links of Interest...
    http://www.apple.com/support/mac101/
    http://www.apple.com/support/switch101/     Switching from PC
    Find Out How (Video)
    http://www.apple.com/findouthow/mac/

  • I have iphone 4 and have never updated itsince i've bought it. now i would like to update it to iOs 7. maybe can i have some problems in doing this due to the fact that i've never updated it until now?

    I have iphone 4 and have never updated itsince i've bought it. now i would like to update it to iOs 7. maybe can i have some problems in doing this due to the fact that i've never updated it until now? thanks in advance for every reply

    Did you follow this article to update your phone?
    iOS 4: Updating your device to iOS 5 or later
    iOS: How to update your iPhone, iPad, or iPod touch
    If your device has modified software installed (jailbreak), you might get problems using the phone after updating it.

  • I have accidentally deleted an sms that I require from my iphone 4s. Can anyone please help me to get this back?

    I have accidentally deleted an sms that I require from my iphone 4s. Can anyone please help me to recover this?

    If it wasn't present the last time you backed up your phone, then you've lost it forever.  There's no "trash" on the iPhone that you can "undelete"

Maybe you are looking for