java
Write a single Java statements to accomplish each of the following:
a) Displaythevalueoftheseventhelementofcharacterarraych.
b) Considering “Scanner in = new Scanner (System.in);”, input a value into
element 5 of one-dimensional double array nums.
c) Initialize each of the four elements of the one-dimensional integer array test to 7.
d) Declare and create an array called table as a float array that has four rows and three columns.
e) Considering the following ArrayList declaration, insert
“test” at the fourth position (index 3) in list.
ArrayList<String> list = new ArrayList<>();
f) Give the method header for method mode that takes two integer arrays freq and answer, and returns a double-precision floating-point result.
g) Considering the following array declaration:
int[][] numberArray = new int [9][11];
write a statement that assigns 145 to the first column of the last row of this array.
a)
answer: ch[6];
because the index values starts from 0 to n-1 n is the lenght of the array
for the seventh element the index will be 6 so the answer is ch[6]
b)
nums[4]=in.nextDouble();
becuase to read the 5th element its index will be 4
to read the double element scannerobject.nextDouble() is used to read the double form the user.
Here scanner object is in so in.nextDouble() is used to read the double and it is stored in nums[4]
so the answer is nums[4]=in.nextDouble();
c)
answer:
int[] test={7,7,7,7}
here the lenght of the array is 4.
and each element is 7.
d)
answer:
float[][] table={{1f,2f,3f},{1f,2f,3f},{1f,2f,3f},{1f,2f,3f}};
float is the data type
table is the name of the float array
and there are 4 rows and 3 columns
Note: we are not suposed to answer more than 4 subparts of the question
Get Answers For Free
Most questions answered within 1 hours.