QUESTION 1:
Look at the following array declaration:
Int[ ] numbers = { 4, 7, 3, 6, 8, 9};
What is the output of the following lines?
//A.
System.out.println(numbers[3]);
//B.
x = 2 * numbers[2] + numbers[4];
System.out.println(x);
//C.
x = 3 + numbers[3]++;
System.out.println(x);
QUESTION 2:
Class Rectangle has two data members, length (type of float) andwidth (type of float).
The class Rectangle also has the following:
//mutator methods
void setLength (floatlen)
{
length =len;
}
//accessor methods
float getLength ()
{
return length;
}
The following statementcreates an array of Rectangle with size 2 :
Rectangle[ ] arrayRectangle=new Rectangle[2];
Is it correct if executing the following statements? What is theoutput? If it is not correct, write the correct one
//A.
arrayRectangle. setLength(12.59);
System.out.println(rectangleSet.getLength());
//B.
arrayRectangle[1].setLength(4.15);
System.out.println(arrayRectangle[1].getLength()):
QUESTION 3:
Use the following int array
int [ ] numbers = { 42, 28, 36, 72,17, 25, 81, 65, 23, 58 }
-Open file data.txt to write.
-then provide the code to write thevalues of the array numbers to the file with the
following format. You must accessthe elements of the array numbers to get the values
-Remember to close the file
Numbers at index 0 = 42
Numbers at index 1 = 28
Numbers at index 2 = 36
Numbers at index 3 = 72
Numbers at index 4 = 17
Numbers at index 5 = 25
Numbers at index 6 = 81
Numbers at index 7 = 65
Numbers at index 8 = 23
Numbers at index 9 = 58
QUESTION 4
Write the code of data type classRainfall_Information_yourLastName including:
*data member with one float array of size 12 tostore the rainfall of 12 months in the year.
* no-argument constructor
*parameterized constructors
QUESTION 1: Look at the following array declaration: Int[ ] numbers = { 4, 7, 3, 6, 8, 9}; What is the output of the fol
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am