Results 1 to 3 of 3

Thread: Nested loop

  1. #1
    Shasool is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Nested loop

    any tips would be appreciated
    Start with a simple program that outputs the behaviour for a given "hardwired" situation:

    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);
        }
    }
    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.

  3. #3
    Shasool is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Nested Loop
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 03-11-2011, 04:39 AM
  2. Issue with nested for loop
    By sunshine64 in forum New To Java
    Replies: 5
    Last Post: 02-03-2011, 03:45 AM
  3. Nested For Loop algorithm
    By but43r in forum Advanced Java
    Replies: 5
    Last Post: 01-11-2011, 09:52 AM
  4. can some one help me with nested loop?
    By keycoffee in forum New To Java
    Replies: 10
    Last Post: 01-25-2010, 03:49 AM
  5. Nested For Loop
    By yuchuang in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 02:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •