Project Euler – Problem 56

Problem 56: Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum? Digital sum, ie: 47 = 4+7=11

package runner;
 
import java.math.BigInteger;
 
class runner
{	
	public static void main (String[] args) throws java.lang.Exception
	{
		long time = System.currentTimeMillis();
 
		int lsum = 0;
		for(int a=2;a<100;a++){
			BigInteger b_a = new BigInteger(""+a);
			for(int b=2;b<100;b++){
				BigInteger pow = b_a.pow(b);
				String powStr = pow.toString();
				int sum = 0;
				for(int i=0;i<powStr.length();i++){
					sum += powStr.charAt(i);
				}
				sum-=48*powStr.length();
 
				if(lsum < sum) lsum = sum;
			}
		}
		System.out.println("lsum:"+lsum);
		System.out.println("time: "+(System.currentTimeMillis() - time));
	}
}