Will give thumbs up for correct answers to the questions. Also really appreciate
ID: 3902005 • Letter: W
Question
Will give thumbs up for correct answers to the questions. Also really appreciate if brief explanation is also provided as well,Thank you
(All questions are about Java)
Short answer 1. (4 x 2 marks) a) Consider the statement: Bee[1 hive new Bee[10241 What type of is hive [5121:7 b) Consider the statement : int y- stored in y. tunt,?ath.randon O·1000)) % 4; List all possible values that could be c) Write a for loop that computes the sum of the numbers between S and 5O in increments of s d) Convert: tor(int start-100 start 1 start-)System.out.printin(start start)s into a While loop. er an array of integers named numbers with values: 12 31 23 1 2. (3 x 2 marks) Consider an array of integers named numbers with values a) What is the value stored in total after the following statements: int total-O; for (int i-Oz í
Explanation / Answer
1.
a) type of hive[512] is Bee class
b) possible values of y are 0,1,2,3
Math.random() generates a random number and mod 4 gives values between 0 to 3
c)
sum = 0;
for(int i=5;i<50;i=i+5)
sum += i;
d)
start = 100;
while(start >= 1){
System.out.println(start * start);
start--;
}
2.
a) final value stored in total is 7
initially total = 0
i = 0:
total = 0 + 1
total = 1
i = 1:
total = 1 + 2
total = 3
i = 2:
total = 3 + 3
total = 6
i = 3:
total = 6 + 1
total = 7
b) final array after the statements is -1 -2 -3 -1 -2 -3 -1
intital array : 1 2 3 1 2 3 1
interating through the loop
i = 0:
numbers[0] = 1 - (2 * 1) = -1
i = 1:
numbers[1] = 2 - (2 * 2) = -2
i = 2:
numbers[2] = 3 - (2 * 3) = -3
similarly for other values
c)
int temp = numbers[1];
numbers[1] = numbers[5];
numbers[5] = temp
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.