top of page

Edabit Java: Can You Spare A Square?, easy difficulty


solving this question in edabit: Can You Spare A Square? // Edabit using a for loop



public class SparedSquare {

public static String tpChecker(int people, int tp) {

int days = -1;

int sheets = 500;

int total = tp * sheets;

int tpSheetPerDay = 57;

int stayHome = 14;

while(total > 0) {

total -= tpSheetPerDay * people;

days++;

}

return days >= stayHome ? "Your TP will last "+ days + " days, no need to panic!" : "Your TP will only last " + days + " days, buy more!";

}

}


3 views0 comments
Post: Blog2_Post
bottom of page