This is my first time using this and I'm having a bit of trouble with arrays. I need to check if the values in an array that the user enters are continuously being squared such as {2, 4, 16, 256}
. Checking if num[1] = num[0] * num[0], num[2] = num[1] * num[1] and so on. Any help would be appreciated.
import java.util.Scanner;
public class PS6Square {
public static void main (String [] args){
Scanner scan = new Scanner(System.in);
System.out.println("How many values would you like to enter?");
String input = scan.next();
int array = Integer.parseInt(input);
int num[] = new int[array];
int i = 0;
boolean result = false;
for(i = 0; i < num.length; i++)
{
System.out.print("Enter a value:\t");
num[i] = scan.nextInt();
if(num[i] == num[i] * num[i])
{
result = true;
}
}
System.out.println("\nThe result is:\t" + result);
}
}