View Single Post
  #2 (permalink)  
Old 03-20-2008, 01:32 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
Using the properties of numbers we can write this
d1 * d1 * d1 * d1 * d1 * d1 * d1 * Math.pow(10, 1000000000000000000000)
Code:
public class Test { public static void main(String[] args) { // d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000 int terms = 7; int n = 1*10+1; long value = n; long powersOfTen = 0; for(int i = 1; i < terms; i++) { value *= n; for(int j = 0; j < i; j++) powersOfTen += 1; } System.out.printf("value = %d * powersOfTen = %d%n" + "expression evaluates to %d * 10^%d%n", value, powersOfTen, value, powersOfTen); System.out.printf("value should = %d " + "powersOfTen should = %d%n", (long)Math.pow(n, 7), 6+5+4+3+2+1); } }
Reply With Quote