looping explanination

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • windx
    New Member
    • Mar 2008
    • 4

    looping explanination

    I really want to know about how two forloop works to iteratiating the values
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by windx
    I really want to know about how two forloop works to iteratiating the values
    Post an example of a for loop you want to be discussed!!!

    We will do the trace for you..

    Sukatoa

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      @OP: suppose you are a loop and you print the value of variable 'jos' three
      times plus the loop counter value; here you are:

      [code=java]
      int jos= 42;
      for (int windx= 0; windx < 3; windx++) { // <-- you
      System.out.prin tln(jos+" "+windx);
      }
      [/code]

      Now suppose I'm also a loop and I activate you four times: Here I am:

      [code=java]
      for (int jos= 0; jos < 4; jos++) { // <-- me
      for (int windx= 0; windx < 3; windx++) { // <-- you
      System.out.prin tln(jos+" "+windx);
      }
      }
      [/code]

      Now try to guess/figure out what gets printed.

      kind regards,

      Jos

      Comment

      • joej231
        New Member
        • Mar 2008
        • 2

        #4
        could you explain this loop please?

        Given a list of integers and an integer variable declared like this:

        List<Integer> list;
        int max;

        and assuming that some values have been added to the list, write a loop which finds the largest value in list and stores it in max.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by joej231
          could you explain this loop please?

          Given a list of integers and an integer variable declared like this:

          List<Integer> list;
          int max;

          and assuming that some values have been added to the list, write a loop which finds the largest value in list and stores it in max.
          Have a look at the Integer.MIN_VAL UE and the Math.max() method.

          kind regards,

          Jos

          Comment

          Working...