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...
A scroll bar contains scroll arrows and a scroll box.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology
The strict DTD is best used for older documents that contain deprecated features.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology
Computers that store Web pages are known as client servers.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology
A ________ chart is useful in comparing values across categories
A) clustered bar B) scatter C) line D) pie
Computer Science & Information Technology