Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class HelloWorld{
- public static void main(String []args)
- {
- //Insantiating variables
- //Multipliedthing is the product of a given 17 integers
- int multipliedthing=0;
- //Finalthing is largest product of 17 integers found so far
- int finalthing=0;
- String numberString= "731671765313362491922511967442657474235534919493496983523127745632623957831816984818694788518438586156789112949495459517379583319528532885511125469874715852386357156932996329522744343557668966489544524452316173185643987111217223831136222989342338381353362766142828644448664523874933589729629491564477239713815158593796866717242712188399879798792274921916997288893776657273331533678812223542189751254545947522435258497711675561364839586446763244157221553975369781797784617464955149298625693219784686224828397224137565756574926147972968652414535147482166374844319989889524345658541227588666881164271714799244429282386346567481391912316282458617866458359124566529476545682848912883142676942242192267155626321111193754421756941658964871984385962455444362981239878799272442849918884581561669791913387549925246368991256717665886116467194577541225698315525593572972571636269561882674282524836823257534275296345";
- //Converting the numbers into an array of ints
- int[] numbers= new int[numberString.length()];
- for (int i=0; i<numberString.length(); i++)
- {
- numbers[i]=Character.getNumericValue(numberString.charAt(i));
- }
- //Finding the product of sets of numbers
- for (int i=0; i<numbers.length-17; i++)
- {
- multipliedthing=numbers[i];
- for (int j=1; j<17; j++)
- {
- multipliedthing*=numbers[i+j];
- }
- //Tests to see if that product is the largest one created
- if (multipliedthing>finalthing)
- {
- finalthing=multipliedthing;
- }
- }
- //Prints the largest thing found
- System.out.println(finalthing);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement