Results 1 to 1 of 1
  1. #1
    Teclis is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default Counting with a sentinel loop

    Java Code:
    while(num > SENT)
             {
                if(PS)
                {
                   System.out.println("This is the" +  num);
                }
    
                groupCount++;
                groupSum = groupSum + num;
    
                if(PS)
                {
                   System.out.println("This is the" + groupCount+ "and the" + groupSum);
                }
    
               num = scan.nextDouble();
    
             }
    To me, at first glance, the groupCount will go up until the sentinel is read in then reset for the next group of numbers. Instead, what it does is keeps counting, instead of finding that in the first group there are 4 numbers then in the second group finding that there are 6 numbers; it totals out to give me 10.

    I figured it out.
    -bash-3.2$ facepalm
    Last edited by Teclis; 03-22-2011 at 08:40 PM.

Similar Threads

  1. sentinel help
    By droidus in forum New To Java
    Replies: 12
    Last Post: 03-04-2011, 03:58 PM
  2. Counting Words
    By Shyamz1 in forum New To Java
    Replies: 9
    Last Post: 03-03-2011, 02:12 PM
  3. Help with Sentinel Loops
    By hedwards09 in forum New To Java
    Replies: 11
    Last Post: 11-07-2009, 08:39 PM
  4. Counting help
    By jksmithson in forum New To Java
    Replies: 1
    Last Post: 11-06-2009, 03:43 AM
  5. Replies: 1
    Last Post: 03-03-2009, 01:46 AM

Posting Permissions

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