Calculating Sum of Digits of a given Number

 

import java.util.*;

public class SumOfDigit {
public static int calculateSum(int n) {
int sum = 0;
if (n >= 0 && n <= 9) {
return n;
}
while (n > 0) {
int digit = n % 10;
sum = sum + digit;
n = n / 10;
}
return sum;
}

public static void main(String args[]) {
int arr[] = { 1234, 2341, 5462, 567342, 1238 };
for (int i = 0; i < arr.length; i++) {
int x = calculateSum(arr[i]);
System.out.println("Sum of the digit of " + arr[i] + " is = " + x);
}
}
}

Google Script for Data Entry Form in Google Spreadsheet

// function to validate the entry made by user in user form function validateEntry (){ // declare a variable and referernece of active goog...