guys, this code calculate the amount of classes that a student needs to take lets say for 17 credits. It will be 5 three credits classes and 2 one credit classes, but I think the loop is kind of unnecessary. could anyone post a more efficient way? thanks
public static void numOfClasses(int credits) { int class3 = 3, class1 = 1, numOfClass; do { if(credits >= 3) { numOfClass = credits / class3; credits -= (numOfClass * class3); System.out.println("3 credits classes: "+numOfClass); } else { numOfClass = credits / class1; credits -= (numOfClass * class1); System.out.println("1 credit classes: "+numOfClass); } }while(credits != 0); }