Post date: Oct 01, 2018 5:14:4 AM
/!\ Midterm Practical will be next week (7)
/!\ Assignment 1 will be on the first class of the week (6)
Flow of Control
3.3 Loops (while / do-while)
Recommended Self-Test Exercises:
p 169-170: Ex. 22-27.
Lab Exercises:
Write a Java program which reads 5 numbers from the user using a loop and computes and displays their average
Write a Java program which computes the sum of all the odd numbers and the sum of all even numbers between 0 and 100
Ask the user to enter a integer number N. Display N factorial.
Write a program that reads 3 grades between 0 and 100. Validate the input to make sure that the user enters valid grades. Calculate the average and display the letter grade of the average (A, B, C, D or F).
Write a Java program which reads unknown number of integers using a scanner and counts the number of odd numbers and the number of even numbers. Assume the input integers are all positive. Use a negative number as a sentinel to stop reading numbers.
Programming Challenges:
Write Java program to check if a number is palindrome in Java. A palindrome can be read in both ways: 121 is palindrome, 321 is not.
Print the following square in Java using loops:
# # # #
# #
# #
# # # #
Extend the exercise 7 to ask the user to input the size of the square to display.
It is difficult to make a budget that spans several years, because prices are not stable. If your company needs 200 pencils per year, you cannot simply use this year’s price as the cost of pencils two years from now. Because of inflation, the cost is likely to be higher than it is today. Write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years from now that the item will be purchased, and the rate of inflation. The program then outputs the estimated cost of the item after the specified period. Have the user enter the inflation rate as a percentage, such as 5.6 (percent). Your program should then convert the percent to a fraction, such as 0.056, and should use a loop to estimate the price adjusted for inflation.
The Fibonacci numbers Fn are defined as follows: F0 is 1, F1 is 1, and Fi+2 = Fi + Fi+1 for i = 0, 1, 2, . . . . In other words, each number is the sum of the previous two numbers. The first few Fibonacci numbers are 1, 1, 2, 3, 5, and 8.
Write a program that allows the user to choose how many Fibonacci numbers to display using a loop.