projecteuler008 - largest product in a series
/* Scott Santarromana, 2010
* projecteuler008 - largest product in a series
*
* Find the greatest product of five consecutive digits in the 1000-digit
* number (See "number" below").
*
*
*/
class Problem008 {
public static void main(String[] args) {
String number = new String(
"7316717653133062491922511967442657474235"
+ "5349194934969835203127745063262395783180"
+ "1698480186947885184385861560789112949495"
+ "4595017379583319528532088055111254069874"
+ "7158523863050715693290963295227443043557"
+ "6689664895044524452316173185640309871112"
+ "1722383113622298934233803081353362766142"
+ "8280644448664523874930358907296290491560"
+ "4407723907138105158593079608667017242712"
+ "1883998797908792274921901699720888093776"
+ "6572733300105336788122023542180975125454"
+ "0594752243525849077116705560136048395864"
+ "4670632441572215539753697817977846174064"
+ "9551492908625693219784686224828397224137"
+ "5657056057490261407972968652414535100474"
+ "8216637048440319989000889524345065854122"
+ "7588666881164271714799244429282308634656"
+ "7481391912316282458617866458359124566529"
+ "4765456828489128831426076900422421902267"
+ "1055626321111109370544217506941658960408"
+ "0719840385096245544436298123098787992724"
+ "4284909188845801561660979191338754992005"
+ "2406368991256071760605886116467109405077"
+ "5410022569831552000559357297257163626956"
+ "1882670428252483600823257530420752963450");
int result = 0, current_result = 1;
for (int i = 0; i < number.length() - 5; i++) {
current_result = 1;
for (int j = i; j < i + 5; j++) {
current_result *= Character.digit(number.charAt(j), 10);
}
if (current_result > result) {
result = current_result;
}
}
System.out.println("Greatest product of"
+ "five consecutive digits in\n"
+ "the 1000-digit number is "
+ result);
}
}