- 10-10-2010 10:51 AM #1WTF 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."
- 10-10-2010 12:01 PM #2
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++
- 04-11-2011 09:37 AM #3WTF 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.
- 05-31-2011 07:49 AM #4Junior 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 */
-
- 02-04-2012 05:50 AM #5
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
.................................................. .................................................. .........



LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks