have to write a JAVA program that'll solve the following problem. What 13 digits give the highest product and what Is said product?? I tried to run the code in Online GDB compiler and got the following 2 last screenshot. This is my code so far and I wish to know if it is correct.... import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] array = new int[1000]; for (int i = 0; i < 1000; i++) { array[i] = sc.nextInt(); } long p = 1; for (int i = 0; i < 13; i++) { p = p * array[i]; } long ma=p; for (int i = 13; i < 1000; i++) { if(array[i-13]!=0) { long np = (p/array[i-13])*array[i]; if(np>ma) { ma=np; } p=np; } } System.out.println(ma); } }
I have to write a JAVA program that'll solve the following problem. What 13 digits give the highest product and what Is said product?? I tried to run the code in Online GDB compiler and got the following 2 last screenshot. This is my code so far and I wish to know if it is correct....
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int[] array = new int[1000];
for (int i = 0; i < 1000; i++)
{
array[i] = sc.nextInt();
}
long p = 1;
for (int i = 0; i < 13; i++)
{
p = p * array[i];
}
long ma=p;
for (int i = 13; i < 1000; i++)
{
if(array[i-13]!=0)
{
long np = (p/array[i-13])*array[i];
if(np>ma)
{
ma=np;
}
p=np;
}
}
System.out.println(ma);
}
}
Step by step
Solved in 2 steps with 1 images