i have this problem with regards to java data

the problem accepts input number and then output the sum of the square from 1 to the n(1 to the no. input) thus, if the input is 4 the output should be 288 because:

1 raise to 1 + 2 raise to 2 + 3 raise to 3 + 4 raise to 4
1 + 4 + 27 + 256 = 288


i have my code but i'm stuck gotta help me outta here

import javax.swing.*;
public class RRunner {
public static void main(String[] args){

    int i; // counter
    int num; // number to be input
    int pw; // power of sum

    num = Integer.parseInt(JOptionPane.showInputDialog("Enter a number: "));
    for( i=1; i<=num; i++ ){
    
        pw = (num*num) + i;
            System.out.println("The answer is "+ pw);
   
    }

}
}
import javax.swing.*;
public class RRunner {
public static void main(String[] args){

int i; // counter
int num; // number to be input
int pw=0; // power of sum

num = Integer.parseInt(JOptionPane.showInputDialog("Enter a number: "));
for( i=1; i<=num; i++ ){
pw += Math.pow(i, i);

}
System.out.println("The answer is "+ pw);
}
}

small change

nice solution! :)
<FAKE SIGNATURE>

commented: Useless. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.