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.

Results 1 to 6 of 6

Thread: HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM

    WRITE JAVA FOR WHILE SYNATX CODE GIVE OUT

    1^1 + 2^2 + 3^3 + 4^4 + 5^5

    Result=3413


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM

    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.

  3. The Following User Says Thank You to Norm For This Useful Post:

    muhammad waqar (December 22nd, 2012)

  4. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    8
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM

    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.
    }

  5. The Following User Says Thank You to matinm90 For This Useful Post:

    muhammad waqar (December 22nd, 2012)

  6. #4
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM

     
    long val = /*start value for val*/ ;
     
    for(int i = 1; i <= /*upper limit*/; /*increment*/)
    {
    val += //mathematical expression for the series
    }

  7. The Following User Says Thank You to aesguitar For This Useful Post:

    muhammad waqar (December 22nd, 2012)

  8. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM

    //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);


    }
    }

  9. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM

    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.

Similar Threads

  1. How to solve “NullPointerException” in my Java Program ?
    By unknowny in forum Java Theory & Questions
    Replies: 8
    Last Post: July 24th, 2012, 04:06 PM
  2. Solve the recurrence in java plzzzzzz
    By inthu in forum Algorithms & Recursion
    Replies: 5
    Last Post: December 13th, 2011, 08:25 AM
  3. java Loop program to place distinct value in a row, column and diagonal
    By javanovoice in forum Loops & Control Statements
    Replies: 3
    Last Post: September 8th, 2011, 08:08 PM
  4. Java Program Loop Possibly needed
    By mikec2500 in forum Loops & Control Statements
    Replies: 1
    Last Post: January 25th, 2011, 01:35 AM
  5. how I can solve this program ?
    By Noni in forum Object Oriented Programming
    Replies: 9
    Last Post: January 20th, 2011, 05:33 PM