Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-28-2008, 05:59 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Exersices
Since I think exercises are fun I will post some in this thread for you guys to try. Hopefully if this is implemented I could give points to completed projects. I hope you enjoy these. If you think you have completed the exercise then post your code for others to see. Hopefully this will become a learning experience for us all.

Exercise 1:
Use recursion to make an algorithm that computes the factorial of a certain number. For instances 2 factorial is 2. 3 factorial is 6.

Sorry for the simplicity of this first exercise, I promise I will make more challenging ways later. I will post another exercise later. If you have one that you would like me to post pm me and I will give you credit and will post it most likely.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-28-2008, 06:53 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
Recursion is fun...you did start easy.

Code:
static int factorial(int temp) { if (temp < 3) { return temp; } else { return temp * factorial(temp - 1); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-28-2008, 07:56 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
@ Chris good job.

Exercise 2:
N number of people keeping flipping their coins until there is a odd man out. Write a program that will find the average number of tries it will take in order for their to be an odd man out. What I mean is if there is 3 people then 2 of them have to have heads and one person has to have tails. or 2 people have to have tails and one person has to have heads. Write this program so that it keeps flipping all the coins and keeps track of the number of tries. Try to find an average number. Bonus for any one who finds the average for up to 10 people.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-28-2008, 08:17 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
Why not just make it not care about the number of people? And you never mentioned how many times to test to get the average. So those are my two parameters.

Code:
static double flip(int people, int flips) { Random r = new Random(); double average = 0; for (int x = 0; x < flips; x++) { int count = 0; int total = 0; while ((total != people - 1) & total != 1) { total = 0; for (int y = 0; y < people; y++) { total += Math.abs(r.nextInt()) % 2; } count++; } average += count; } return average / flips; }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-28-2008, 08:31 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Think of it this way Chris.

Ten people are in a line they all toss their coins. They check to see if there is an odd man out. If not they all flip their coins again. The program is suppose to try and figure out the average number of flips it will take for N number of people to get an odd man out.
__________________
My IP address is 127.0.0.1

Last edited by Zosden : 05-28-2008 at 08:48 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-28-2008, 08:59 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
And how does mine not do that?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-28-2008, 09:08 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
how does urs check to see if there is an odd man out.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-28-2008, 09:24 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
it does a running total of random numbers (example 0 for heads 1 for tails). A 1 or # of people -1 would mean an odd man out.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-28-2008, 09:33 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
ok good job sorry I can't really test it out cause im on my iPhone. Could you please post the average number of flips for n = 3 through n = 10.

Exercise 3:

This one should shock you guys. If you take two random integers and put them in a fraction the probability that they will be in lowest terms has to do with pi. Here's the formula pi = the square root of (6 / (number of fractions in lowest terms / number of tries)).
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-29-2008, 06:06 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Exercise 4:

Write a program where one computer is a server and the other is a client. The server will ask the client if he wants to hear a joke then if the client sends back yes the server sends a joke. This can all be done with system.out but it needs to be networked. I would also apperiated it if people would pm me some of their ideas.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-29-2008, 03:48 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
I will now only post an exercise once a day.

Exercise 5:

This one is a bit longer, but I thought it was fun to make. I think I'm going to leave it open and see your creativity at hand. If you guys would like I can post mine too.
Here's the exercise: make a screensaver like app that just looks like a screensaver. Bonus if you actually make it an actual screensaver.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 06-03-2008, 06:54 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Exercise 6:

Make an appilcation that has one class the implements runnable that takes in a value and increments it then prints out the new value. Then in your main method make an array of these that keep incrementing the same value.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 12:44 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org