Instructor
Demo Programming Problems
Problem D1
Write a program to find the
sum of the first n positive integers.
Your program should read values of n (whole numbers) one per line from
standard
input (without prompting) and send the results to standard output, one
per line. You may assume the input is a whole number, but it may be
non-positive.
Problem D2
Write a program to read a list of whole numbers. Find the product
of all the positive numbers, the sum of all the negative numbers, and
the count of the number of zeroes. Your program should read the list of
numbers on one line from
standard
input (without prompting) and send the results to standard
output. Order the results: product, sum, count and leave one
blank between them.
Problem D3
Write a program to find the position of the first and last 9 in a list
of whole numbers. Your program should read the list of numbers on one
line from
standard
input (without prompting) and send the results to standard
output.
Order the results: first position, last position and leave one blank
between them.
Problem D4
Write a program to compute the percentage of comment lines in a Java
source code file. A comment line is one whose first non-blank character
is a slash or an asterisk. Ignore blank lines.
|