Results 1 to 3 of 3
Thread: Nested loop
- 10-23-2011, 06:10 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
Nested loop
Hello,
I need to write code for the following:(any tips would be appreciated)
describe the three-way choice animals face when confronted with a threat.
That is: If we are not noticed, we freeze. If we are noticed and are not trapped, we run. If we are
noticed and are trapped, we fight. Your program should generate the following sample sessions,
depending on the situation. Italicized characters are keyboard entries.
Sample session 1:
Noticed? (y/n): n
Freeze
Sample session 2:
Noticed? (y/n): y
Trapped? (y/n): n
Run
Sample session 3:
Noticed? (y/n): y
Trapped? (y/n): y
Fight
- 10-23-2011, 06:42 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Re: Nested loop
Start with a simple program that outputs the behaviour for a given "hardwired" situation:any tips would be appreciated
Only once you have the decision (as described in the question) implemented correctly for different values of noticed and trapped need you move on to consider how you could (a) prompt the user for input and (b) repeat the whole process. This may or may not involve a nested loop.Java Code:public class Whatever { public static void main(String[] args) { boolean noticed = false; boolean trapped = false; String output; // your code here System.out.println(output); } }
- 10-23-2011, 05:10 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Nested Loop
By sehudson in forum New To JavaReplies: 2Last Post: 03-11-2011, 03:39 AM -
Issue with nested for loop
By sunshine64 in forum New To JavaReplies: 5Last Post: 02-03-2011, 02:45 AM -
Nested For Loop algorithm
By but43r in forum Advanced JavaReplies: 5Last Post: 01-11-2011, 08:52 AM -
can some one help me with nested loop?
By keycoffee in forum New To JavaReplies: 10Last Post: 01-25-2010, 02:49 AM -
Nested For Loop
By yuchuang in forum New To JavaReplies: 1Last Post: 07-08-2007, 01:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks