119_2010_Spring_Lab09

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online