WRITE JAVA FOR WHILE SYNATX CODE GIVE OUT
1^1 + 2^2 + 3^3 + 4^4 + 5^5
Result=3413
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.
If you don't understand my answer, don't ignore it, ask a question.
muhammad waqar (December 22nd, 2012)
I am not sure what your code is but one way of writing this could be:
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. }
muhammad waqar (December 22nd, 2012)
long val = /*start value for val*/ ; for(int i = 1; i <= /*upper limit*/; /*increment*/) { val += //mathematical expression for the series }
muhammad waqar (December 22nd, 2012)
//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.
If you don't understand my answer, don't ignore it, ask a question.