THE NEW ERA ZONE
Would you like to react to this message? Create an account in a few clicks or log in to continue.

JAVA( Sum of 1st 10 Natural Numbers)

2 posters

Go down

JAVA( Sum of 1st 10 Natural Numbers) Empty JAVA( Sum of 1st 10 Natural Numbers)

Post by djay03 Sun Apr 13, 2014 1:41 am

Logic: Sum of previous two numbers will give us next number.


public class Sum10
{
public static void main(String args[])
{
int n, sum=0;
for(n=1;n<=10;n++)
{
sum+=n; //or sum=sum+n;
}
System.out.println(sum);
}
}


OUTPUT
____________________________

55
djay03
djay03

Posts : 23
Points : 61
Join date : 2014-04-01
Age : 31

Back to top Go down

JAVA( Sum of 1st 10 Natural Numbers) Empty Re: JAVA( Sum of 1st 10 Natural Numbers)

Post by Admin Mon Apr 14, 2014 9:31 am

Cool 
Admin
Admin
Admin
Admin

Posts : 11
Points : 9
Join date : 2014-03-31
Age : 31
Location : PHILIPPINES

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum