WRITE JAVA FOR WHILE SYNATX CODE GIVE OUT
1^1 + 2^2 + 3^3 + 4^4 + 5^5
Result=3413
Printable View
WRITE JAVA FOR WHILE SYNATX CODE GIVE OUT
1^1 + 2^2 + 3^3 + 4^4 + 5^5
Result=3413
You have a problem with your keyboard's cap lock key. All the letters in your post are uppercase.
Can you fix your post to be in normal case?
Post the code you are working on so we can see what your problem is.
I am not sure what your code is but one way of writing this could be:
Code :int i = 0; while(true) { take the power of i to itselft (ie. i^i) then add it to some instance variable. after that increment i. keep doing this forever and ever, unless you need to have a limit for how long it needs to go. in which case the while loop parameter could be "while(i < 40)" for example. }
Code java:long val = /*start value for val*/ ; for(int i = 1; i <= /*upper limit*/; /*increment*/) { val += //mathematical expression for the series }
//this program give output 1^3 + 2 ^3 + 3^3 + 4^4....upto n input numbers.......
//but now i wana to get out put in this form 1^1 + 2^2 + 3^3 + 4^4 .....upto n input numbers......
//pls help me to make this program..........
import java.util.*;
class cubeseries{
public static void main(String arg[]){
int s=0 , num ,i;
Scanner input = new Scanner(System.in);
System.out.print("ENTER NUMBER : ");
num = input.nextInt();
for(i = 1 ; i <= num ; i++)
s = s+i*i*i;
System.out.print(s);
}
}
The code does only this:
i*i*i is i^3
Try writing a loop to compute the power instead of using a single expression on one line.
if x = i
then x*i is i*i
then x*i is i*i*i
and again x*i is i*i*i*i
Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.