Advertisement
DEMcKnight

Code

Aug 14th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. import java.util.*;
  2. public class HelloWorld{
  3.  
  4.     public static void main(String []args)
  5.     {
  6.         //Insantiating variables
  7.         //Multipliedthing is the product of a given 17 integers
  8.         int multipliedthing=0;
  9.         //Finalthing is largest product of 17 integers found so far
  10.         int finalthing=0;
  11.        
  12.         String numberString= "731671765313362491922511967442657474235534919493496983523127745632623957831816984818694788518438586156789112949495459517379583319528532885511125469874715852386357156932996329522744343557668966489544524452316173185643987111217223831136222989342338381353362766142828644448664523874933589729629491564477239713815158593796866717242712188399879798792274921916997288893776657273331533678812223542189751254545947522435258497711675561364839586446763244157221553975369781797784617464955149298625693219784686224828397224137565756574926147972968652414535147482166374844319989889524345658541227588666881164271714799244429282386346567481391912316282458617866458359124566529476545682848912883142676942242192267155626321111193754421756941658964871984385962455444362981239878799272442849918884581561669791913387549925246368991256717665886116467194577541225698315525593572972571636269561882674282524836823257534275296345";
  13.        
  14.         //Converting the numbers into an array of ints
  15.         int[] numbers= new int[numberString.length()];
  16.         for (int i=0; i<numberString.length(); i++)
  17.         {
  18.             numbers[i]=Character.getNumericValue(numberString.charAt(i));
  19.            
  20.         }
  21.        
  22.         //Finding the product of sets of numbers
  23.         for (int i=0; i<numbers.length-17; i++)
  24.         {
  25.             multipliedthing=numbers[i];
  26.             for (int j=1; j<17; j++)
  27.             {
  28.                 multipliedthing*=numbers[i+j];
  29.             }
  30.        
  31.             //Tests to see if that product is the largest one created
  32.             if (multipliedthing>finalthing)
  33.             {
  34.                 finalthing=multipliedthing;
  35.            
  36.             }
  37.          }
  38.        
  39.         //Prints the largest thing found
  40.         System.out.println(finalthing);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement