0% found this document useful (0 votes)
4 views

Tutorial 4

The document outlines a series of programming activities in Java, including tasks to create programs for generating Fibonacci series, identifying Armstrong numbers, manipulating arrays, and simulating a phone book. Each activity specifies the requirements and deliverables, such as specific Java files to be created. Additionally, there are extra activities for further practice, including filling arrays with specific sequences and computing maximum and minimum values in an array.

Uploaded by

vthanhthanh69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Tutorial 4

The document outlines a series of programming activities in Java, including tasks to create programs for generating Fibonacci series, identifying Armstrong numbers, manipulating arrays, and simulating a phone book. Each activity specifies the requirements and deliverables, such as specific Java files to be created. Additionally, there are extra activities for further practice, including filling arrays with specific sequences and computing maximum and minimum values in an array.

Uploaded by

vthanhthanh69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming 1

Tutorial 4
Activity 1
Write a program in Java to print the Fibonacci series up to a given number (entered by user).
Fibonacci is a popular number series in which, starting from the 3rd number, the number is equal
to the sum of the previous two numbers. The first two numbers are 0 and 1.

Deliverable

Fibonacci.java

Activity 2
An Armstrong’s number is 3-digit number for which sum of cube of its digits are equal to itself.
For example, 371 is an Armstrong number because of 3*3*3 + 7*7*7 + 1*1*1 = 371). Write
Java program to find and print out all Armstrong’s numbers between 100 and 999.

Deliverable

AmstrongNumbers.java

Activity 3
Carry out the following tasks with an array:

a. Allocate an array a of ten integers.


b. Put the number 17 as the initial element of the array.
c. Put the number 29 as the last element of the array.
d. Fill the remaining elements with -1.
e. Add 1 to each element of the array.
f. Print all elements of the array, one per line.
g. Print all elements of the array in a single line, separated by commas.

Deliverable

ArrayPractice.java
Activity 4
Write a program that:

1. Declares an array of Strings.


2. Prints out all the elements of this String array once.
3. Reverses the order of values in the String array.
4. Prints out all the elements of this String array again (after reversing the order).

(*) Note: Do not create another array to hold the result.

Deliverable

ReverseStringArray.java

Activity 5
Write a program that simulates a small phone book. An array is used to store a list of names and
another array is used to store the phone numbers that go with each name. For example, Michael
Myers’ phone number is 333-8000 and Ash Williams’ phone number is 333-2323.

This program allows the user to look up a phone number by entering the person’s name or part of
his name. The program does this searching function in a case-insensitive manner. The program
should display a suitable message if the name is not found in the phone book.

Sample output 1

Enter name to look up:


michael
A result is found for "Michael Myers".
The phone number is: 333-8000

Sample output 2

Enter name to look up:


quan
No result is found for "quan".

Deliverable

ArrayPhoneBook.java
Activity 6
(extra)

Write code that fills an array values with each set of numbers below.

a. 1 2 3 4 5 6 7 8 9 10
b. 0 2 4 6 8 10 12 14 16 18 20
c. 1 4 9 16 25 36 49 64 81 100
d. 0 0 0 0 0 0 0 0 0 0
e. 1 4 9 16 9 7 4 9 11
f. 0 1 0 1 0 1 0 1 0 1
g. 0 1 2 3 4 0 1 2 3 4

Deliverable

ArraySequences.java

Activity 7
(extra)

Write Java code for a loop that simultaneously computes both the maximum and minimum of an
array.

Deliverable

ArrayMinMax.java

Submission
Submit a zip file containing all Java programs to this tutorial’s submission box in the course
website on FIT Portal.

You might also like