Heavy numbers calculation in Java

A function to calculate whether or not a number is heavy might look something like:
public boolean isHeavy(int number) {

String asString = "" + number;

 int sumOfDigits = 0;
 for(int i = 0; i <asString.length(); i++) {
     sumOfDigits += Integer.parseInt(asString.charAt(i) + "");
 }

 return (sumOfDigits / (double)asString.length()) > 7d;

}

Browse More Popular Posts

Leave a Comment