Question: Q 1 . Solve the following problems with Java codes for the following two int type arrays: int [ ] values A = { 1
Q Solve the following problems with Java codes for the following two int type arrays:
int values ;
int values ;
a Swap the contents of the abovementioned arrays valuesA and values :
b Merge the contents of the above mentioned arrays values A and values into a new int type
array called valuesc. Make sure to declare and create values with proper size.
c Find the total sum of the elements in valuesA, and also find the average value. Now print both
the total sum and the average with printf with proper format specifier. The average will have
total field width of digits after the decimal and right justified. Also print the following String
variables in the same print statement:
String msgSum "The sum of all the elements in array valuesA ;
String msgAverage "The average of the elements in array values ;
d Add to all the elements in array valuesB.
e Shift all the elements of the array valuesA by moving one element to the left:
values values
Make sure to set the boundary condition for the loop control variable to be set to:
valuesA.length
f Shift all the elements of the array values B by moving one element to the right;
g Update the elements of array valuesB by swapping the neighboring two elements if lower indexed element is larger than the higher indexed element. Make sure to set the boundary condition for the loop control variable to be set to: i valuesB.length
IfvaluesBi valuesBi
swap the elements if the condition is met
Print the array contents comma separated and observe the output.
h Use the following nested for loops and apply the same swapping condition and logic for the array valuesB.
forint i ; i valuesB.length ; i
for int j ; j valuesB.length I; j
swap the elements if the condition is met
Print the array contents comma separated and observe the output.
Q Write java codes using for loop to Count the total number of vowels in the string "The greatest glory in living lies not in never falling, but in rising every time we fall." Use for loop.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
