Você está na página 1de 2

KING SAUD UNIVERSITY

COLLEGE OF COMPUTER AND INFORMATION SCIENCES


COMPUTER SCIENCES DEPARTMENT

CSC 111: Introduction to Lab HW, Week 9, counter


Programming with Java

control loop

1st Semester 1435-1436

Assignment Policy:
1.

Late assignments will NOT be accepted.

2.

Cheating is forbidden in this course, and will be considered a zero mark.

3.

For any problem, you need to show steps for solving the problem and then
show your implementation (code).

4.

In your code, comments have to be clearly written for each step and
variable names should have a clear meaning.

5.

Your submitted work has to be neat and clean.

6.

Assignments should be stapled or placed in an unsealed envelope.

7.

Please clearly write your name, section number, and student number.
Substantial departures from the above guidelines will NOT be graded.

Q1: Write a program to count small and capital letters in a


sentence.
Enter your sentence:
Welcome to CSC111
Capital: 4
Small: 8
Q2: Write a program to calculate the summation between two
numbers inclusive. Where, the two numbers are entered by the
user.

Enter the first number: 4


Enter the second number: 7
The summation is: 22

Enter the first number: 5


Enter the second number: 2
The summation is: 14

* Note that the 2nd number might be smaller than the 1st and in both
cases you need to find the sum.
Q3: write a program that asks the user to enter an integer N
then compute f(n)
Where f(n) :
F(0)=3
F(n+1)=3/4*f(n)+4
Enter the
f(0)
f(1)
f(2)
f(3)
f(4)
f(5)

Nth term: 5
= 3.00
= 6.25
= 8.69
= 10.52
= 11.89
= 12.92

Note that: print only two numbers after the point.


Q4) A box of cookies can hold 24 cookies and a container can
hold 75 boxes of cookies. Write a program that prompts the
user to enter the total number of cookies. The program
then outputs the number of boxes and the number of
containers to ship the cookies.
Note : each box must contain the specified number of
cookies and each container must contain the specified
number of boxes. If the last box of cookies contains less
than the number of specified cookies, you can discard it, and
output the number of leftover cookies. Similarly, if the
last container contains less than the number of specified
boxes, you can discard it, and output the number of leftover
boxes.

Você também pode gostar