Lab Assignment
1
CS202, Summer 2006
Please upload your source code files using CSNS.
Note that file
uploading will be disabled automatically after the lab ends, so please
turn in your work on time.
1.(10pt) Write a program that reads an integer number consisting of
only
0's and 1's, computes and outputs the binary, octal, and hexadecimal
values of the number. For example, if the input number is 101, the
binary, octal, and hexadecimal values are 5, 65, and 257, respectively.
Use Scanner
for input and System.out
for output.
2.(10pt) Write a program which does the following:
- Create three 2-dimensional arrays a, b, and c,
where the size of each array is 8 by 8, the elements of a and b
are random integers between 10 and 20, and each element c[i][j]
of c is the sum of a[i][j] and b[i][j].
- Implement a method print2DArray which takes a
2-dimensional integer array as parameter and prints out the elements in
the array.
- Output a, b, and c using the print2DArray
method.
HINT: the method Math.random()
will return a random number between 0 and 1.