Horizons
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Java Practice

2 posters

Go down

Java Practice Empty Java Practice

Post  Admin Sun Sep 11, 2011 1:33 am

So, since we are complete beginners at java why don't we set some practice goals on simple programs, try to create a program that will achieve the goal and compare and discuss.

First problem.

30 cookies are need to feed a part. A tray can bake 5 cookies at a time. How many trays do you need to feed the party?

Admin
Admin

Posts : 42
Join date : 2011-09-10

https://horizonchaser.forumotion.com

Back to top Go down

Java Practice Empty Re: Java Practice

Post  Nero Sun Sep 11, 2011 4:29 am

6 trays worth of cookies.Also, the trays themselves cannot feed the party.

You and your clever wording.....

Nero
Nero

Posts : 38
Join date : 2011-09-10

Back to top Go down

Java Practice Empty Re: Java Practice

Post  Admin Sun Sep 11, 2011 5:01 am

Great you know basic arithmetic.

But the point of this excercise is to create a program that'll will find the answer for you.

Code:

import static java.lang.System.out;

class HowManyCookies {
   
   public static void main(String args[])   {
      int cookies = 1;
      int cookiesPerTray = cookies/5;
      int cookiesToFeedEveryone = 30;
      
         do {
            cookies++;
            out.println(cookiesPerTray + " trays to feed everyone");
         } while(cookies<cookiesToFeedEveryone);
            
         }
         
       }

I tried it quick, it's not working right, now we can discuss it. That's how these excericse works.

Admin
Admin

Posts : 42
Join date : 2011-09-10

https://horizonchaser.forumotion.com

Back to top Go down

Java Practice Empty Re: Java Practice

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum