Hello and welcome to our community! Is this your first visit?
Register

Results 1 to 5 of 5
  1. #1
    WTF Groupie Array
    Join Date
    Sep 2010
    Location
    friends heart
    Posts
    125
    Thanks
    0
    Thanked 1 Time in 1 Post

    A simple java program sum of n number

    Hey guy i am in big problem.Actually i don't having much knowledge about Java.I am familiar only with Java.I don't have much knowledge about programing.So guys help me in writing a program on to above topic "A simple Java programing sum of n number using class,object and methods."

  2. #2
    Super Moderator Array
    Join Date
    Sep 2010
    Posts
    21,701
    Thanks
    16
    Thanked 119 Times in 102 Posts


    So, where are you stuck ?
    I mean where is the difficulty ?
    If you show the code you have developed then we can help you, I don't think we are here to complete your homework , we can clear doubts and you should try yourself
    Online tutorial for java can be found @ Java Developer Tutorials and Online Training
    Also,the abstract of programming is similar to C++

  3. #3
    WTF Lurker Array
    Join Date
    Apr 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts


    It’s a visual, flexible, meaningful, and systematic approach to effective and efficient learning through the use of an active, cognitive, inquiry-based, and constructive process.

  4. #4
    Junior Member Array
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts


    i hope this will help u
    ****** Java Program To Print Sum Of 'n' Number ******/

    class Add
    {
    public static void main (String args[])
    {
    int n = 15;
    int sum = 0;
    for(int i = n;i>=0;i--)
    sum = sum + i;
    System.out.println("Sum = "+ sum);
    }
    }

    /*************** OUTPUT *************
    * *
    * Sum = 120 */

  5. #5
    WTF Restricted Array
    Join Date
    Nov 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    An alternative solution to the first problem with summing up to n..

    int n = 50; //Just representing the user input.
    for (int i = 0; i < 1; i++) {
    int sum = (n * (n + 1)) / 2;
    }

    System.out.println(sum);

    It's using a loop and that was the requirement, right?!

    I notice it's in your code, the formula of an arithmetic sum. It's very useful in programming and math so remember it


    .................................................. .................................................. .........




 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •