Q:

Switch Statement and Case

I am making code for my CPSC class and I have to print up to a case number that is set for the int.   When I enter "2", the code prints "two potato" eight times instead of "One potato, two potato". 
Here is my code I have: 
public class Potato {

public Potato() {
}

public void count(int c) {     

    for (int i = 0; i < 8; i++) {   
        switch (c % 8) {
            case 1:  System.out.println("One potato"); break;
            case 2:  System.out.println("two potato"); break;
            case 3:  System.out.println("three potato"); break;
            case 4:  System.out.println("four..."); break;
            case 5:  System.out.println("five potato"); break;
            case 6:  System.out.println("six potato"); break;
            case 7:  System.out.println("seven potato"); break;
            case 8:  System.out.println("more!");  break;
            default: break; 
        }
    }

}
}

I think my problem is my for-loop, not too sure though, since I am here asking for help.  Thanks in advance! 

A:

This should do the trick.  As others have said, you should use i%8.  However, for this to work you should also start with i=1 since 0%8 = 0.  And your case 8 should be changed to case 0. 
for (int i = 1; i <= c; i++) {
    switch (i % 8) {
        case 1: System.out.println("One potato"); break;
        case 2: System.out.println("two potato"); break;
        case 3: System.out.println("three potato"); break;
        case 4: System.out.println("four..."); break;
        case 5: System.out.println("five potato"); break;
        case 6: System.out.println("six potato"); break;
        case 7: System.out.println("seven potato"); break;
        case 0: System.out.println("more!");  break;
        default: break;
    }
}

