# Introduction to Computer Programming (CMPS 200) by moti

VIEWS: 8 PAGES: 1

• pg 1
```									                                                                        Faculty of Arts & Sciences
Department of Computer Science
CMPS 200—Introduction to Programming
Assignment 3 – Due Friday Oct 31, 2008

Objectives and Instructions.

     The objective of this assignment is to write some simple programs that use the if and while statements,
compile, and run them. After writing each program using Microsoft notepad or wordpad, compile the program
in the command prompt using the command “javac program.java”. Then run the program using the command
“java program ...”, where the “...” represents the input to the program. Include printouts of each program and
sample runs for each program in your submission. Your submission should be a printout that you bring to
class on Friday October 31.

Exercises

I.     Write a program that takes three positive floating point values (doubles) as command line arguments and
prints “false” if any one of them is greater than or equal to the sum of the other two, and “true” otherwise.
This program tests if the three values could be the lengths of the sides of a triangle.

Suppose now that some of the numbers can be negative (in which case they obviously cannot be the lengths
of the sides of a triangle). Either change your program to deal with this case, or explain why no change is
needed.

II.     Write a program that takes three double values x, v, and t as command line arguments and prints the value
of x + vt – gt2/2, where g is the constant 9.78033.

III.     Write a program that takes a single positive integer value n as a command line argument and prints the sum
of the first n positive integers, i.e., 1 + 2 + …+ n-1 + n.

IV.       Write a program that takes a single positive integer value n as a command line argument and prints n
factorial.

V.       Write a program that takes a single positive integer value n as a command line argument and prints all the
powers of 2 that are less than or equal to n.

Submission Instructions

     Turn in a printout of the source code and sample runs for each program. Be sure to include more than one
sample run for each program.

```
To top