Question 9 : Write a program in Java to print the sum of the first ten numbers using the for loop.
Java Program :
class sum
{
public static void main()
{
int s=0,i;
for(i=1;i<=10;i++)
s=s+i;
System.out.print("Sum : "+s);
}
}
Output :
Sum : 55
Java Program :
class sum
{
public static void main()
{
int s=0,i;
for(i=1;i<=10;i++)
s=s+i;
System.out.print("Sum : "+s);
}
}
Output :
Sum : 55
Hi, in this code i found some small bug, that is with out using the objects of string ,that means (string object[]),there should an exception while run the code , and your class name is in lower case. hope you are correct it ,
ReplyDeletethank you.
how to correct that bug??(string arg[]) one...??
Deleteqwertyuiopasdfghjllzxvcbmmmmkhgvdtyiojj++15/:))4480.112 6 2 587554*/4%=:,d f g dzrxfz, ex
ReplyDelete