2. <STUDENT NAME>
<SECTION>
<DATE>
I. OBJECTIVES:
At the end of the experiment, students must be able to:
Cognitive
a) understand how single and multi-dimensional array executes
b) understand the logic of arrays declaration and accession.
c) understand how arrays are manipulated and used
.
Psychomotor:
a) construct a program using arrays
b) compile and debug the error of the program
Affective
a) appreciate the concept behind this experiment
II. BACKGROUND INFORMATION
Array is a sequence of objects of the same type and packaged together under one identifier name. The
first element in an array is at position zero: array [0]. There are three steps to create an array:
Declaration, Construction and Initialization.
Declaring one-dimensional
data_type name_of_array[integer_expression];
Example:
Referencing an element in a one-dimensional array
3. The syntax is:
<array name> [<index>]
Array Assignment
Example:
Array Controlling
III.EXPERIMENTAL PROCEDURE:
1. Create a program that will accept a decimal value input and then choose to either
convert it to one of the following number systems:
1 – Decimal to Binary
2 – Decimal to Octal
3 – Decimal to Hexadecimal
USE ARRAYS TO FORM THE NEWLY CONVERTED NUMBER
Sample Output:
Enter a positive decimal value: 14
value to which number system:
1 – Decimal to Binary
2 – Decimal to Octal
3 – Decimal to Hexadecimal
Enter choice: 1
Equivalent of 14 in binary is 1110
4. 2. Write a complete Java program that will fill an array with int values read in from
the keyboard, one per line, and outputs their sum as well as all the numbers read in,
with each number annotated to say what percentage it contributes to the sum. Your
program will ask the user how many integers there will be, that will determine the
length of the array.
Sample Output:
How many integers will you enter?
4
Enter 4 integers, one per line:
2
1
1
2
The sum is 6.
The numbers are:
2 which is 33.33% of the sum.
1 which is 16.67% of the sum.
1 which is 16.67% of the sum.
2 which is 33.33% of the sum
3. Create a program that will store student information in two dimensional array
studentarr[3][3], the program should be able to display the names of the students
and their corresponding grades and averages.
Studentarray[3][3]={{“peter”, 75,77},
{“clark”, 78, 80},
{“logan”,82,84}};
5. IV. QUESTION AND ANSWER:
1. Why is it necessary, being a programmer, to use arrays?. What are the risks of not using
arrays?
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
__
2. When do usually single dimensional array is used?
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
__
6. IV. QUESTION AND ANSWER:
1. Why is it necessary, being a programmer, to use arrays?. What are the risks of not using
arrays?
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
__
2. When do usually single dimensional array is used?
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
__