KING FAHD UNIVERSITY OF PETROLEUM & MINERALS

advertisement
KING FAHD UNIVERSITY OF PETROLEUM & MINERALS
Information and Computer Science Department
ICS-201 Introduction to Computer Science
Lab 01: Review of ICS 102
Objectives: Review of ICS 102 material
Exercise 1
Write a program that reads a word from the user. Any word entered by the user is
assumed to start with a consonant (not a vowel!). Then, the program moves the
consonant to the end of the word and moves all the remaining characters forward and
adds at the end of the word "ay". For example, if the user enters bad, the program
prints adbay. Moreover, if the user enters the word groovy, the program, then, prints
roovygay.
Hint: Make sure to convert the inputted word to lower case before processing it.
Example execution:
Please enter a word:
Bad
The encoded word is:
adbay
Exercise 2
The value of  can be determined by “Wallis’s formula” as:

2

2 2 4 4 6 6
* * * * * *....
1 3 3 5 5 7
Write a complete Java program to calculate the value of  using the above formula.
Stop your loop when the numerator reaches 102.
Exercise 3
Write a Java program which prompts a user to enter 200 integer numbers that are
between 0 and 10 inclusive. Then the program prints the count of how many 0s were
entered, how many 1s were entered, how many 2s were entered, and so on up to how
many 10s were entered.
Exercise 4
Write a Java program that does the following
- Reads 16 integers in to a 4 by 4 2-D array called R.
- Prints the sum of each of the diagonals of R.
- Swaps row 1 elements of R with row 2 elements of R.
- Prints the sum of each row
- Prints the sum of each column
Download