Write a fragment of code that will compute the sum of the first n positive odd integers. For example, if n is 5, you should compute 1 + 3 + 5 + 7 + 9.
What will be an ideal response?
```
int sum = 0;
int odd = 1;
for(int i=0; i
odd += 2;
}
System.out.println("The sum of the first " + n
+ " odd numbers is " + sum);
```
This code is in Fragments.java.
Computer Science & Information Technology
You might also like to view...
The compression ________ indicates the reduction in size from the original size to the packed size
A) ratio B) measure C) quotient D) aspect
Computer Science & Information Technology
An embedded object maintains the structure of the original application and maintains a connection to the source file
Indicate whether the statement is true or false
Computer Science & Information Technology