{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

119_2010_Spring_Lab09

# 119_2010_Spring_Lab09 - CSci 119 Spring 2010 Lab#9...

This preview shows pages 1–2. Sign up to view the full content.

1 CSci 119: Spring 2010 Dr. C. Shin Lab #9: Repetition Statements March 29, 2010 (Monday) In-Lab: 1. Write a Java application program that computes the following sums using a for loop. Name your program file “Loops1.java”. Remember to print the results using the standard output. Do not modify what is already given to you in the program, Loops1.java, and only add your code where it says “INSERT YOUR CODE HERE”. (1) 3 + 6 + 9 + … + 96 + 99 initial value = 3, final value = 99, and step = +3 (2) 1 + 1/3 + 1/5 + 1/7 + … + 1/97 + 1/99 initial denominator = 1, final denominator = 99, and denominator step = +2 Hints : Here, the numerator is always 1. What changes is the denominator so that the statement being repeated is 1/i where i is the loop control variable. Integer divisions result in integer answers. For example 1/2 is 0. If you want an answer 0.5 (which is a double value) for 1/2, the division must be a double division. Hence, the repeated statement , 1/i, which is an integer division, should be a double division: 1. / i, 1.0 / i, (double)1 / i, 1 / (double)i, (double)1 / (double) i, etc. among many possibilities.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern