I want to print an array of size n, where each element is pow(i,i),i ranging from 1 to n. i.e. if I input n = 4, it should return me an array A = {1, 4, 27, 256}. This is because power(1,1) = 1, power(2,2) = 4, power(3,3) = 27 and power(4,4) = 256.
But, when I try to run the below code, it is not giving any output.
import java.io.*;
import java.util.*;
import java.lang.Math;
public class Main
{
public static void main(String[] args)
{
Main s = new Main();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
double[] A = new double[n];
int j ;
for(j = 0; j <= n; j++)
{
A[j] = Math.pow(j+1, j+1);
//System.out.println(A[j]); --> 1
}
System.out.print(A);
System.out.println(A); //-->2
for (int i=0; i<A.length; i++)
{
System.out.print(A[i]+" "); // --> 3
}
}
}
When I try to remove commented quotes for equation 1, it is printing me the values. But neither of equation 2 or 3 is helping me to print the array.
for(j = 0; j < n; j++). To print the result you can useSystem.out.println(Arrays.toString(A));