//How to add 10 natural numbers in java
public class M
{
public static void main(String args[])
{
int sum=0;
for(int i=1;i<=10;i++)
{
sum=sum+i;
}
System.out.println("Sum of 10 natural numbers is: "+sum);
}
}
OUTPUT:
Sum of 10 natural numbers is: 55
public class M
{
public static void main(String args[])
{
int sum=0;
for(int i=1;i<=10;i++)
{
sum=sum+i;
}
System.out.println("Sum of 10 natural numbers is: "+sum);
}
}
OUTPUT:
Sum of 10 natural numbers is: 55
No comments:
Post a Comment