Note that there are some explanatory texts on larger screens.

plurals
  1. PO'if' and 'for' loop questions
    primarykey
    data
    text
    <p>This will be my last question for the evening and a while. I have worked my way through a 100 mark Java assessment and I am now stuck on my final two points. If anyone could help me out, it would be greatly appreciated. I am tired, feeling like a grade-A nub and just want it over with!</p> <p><strong>Study the two instance methods below and then select only the options that are correct.</strong></p> <pre><code>public char[] methodA() { char[] alphas = {'s', 't', 'e', 'a', 'm'}; char temp = alphas[0]; int i = 0; while (i &lt; alphas.length - 1)//1 { alphas[i] = alphas[i+1]; //2 i++; } alphas[alphas.length-1]=temp; return alphas; } public char methodB() { char [] alphas = {'s','a','u','s','a','g','e'}; char first = alphas[0]; for (int i= 1; i &lt; alphas.length; i++) //3 { if (alphas[i] &lt; first) //4 { first = alphas[i]; } } return first; } </code></pre> <ol> <li><p>The assignment statement labelled //2 will put a copy of the char element one to the right of the current element in alphas into the current element in alphas. </p></li> <li><p>The for loop header labelled //3 will be evaluated 7 times. </p></li> <li><p>The if statement labelled //4 will update the value held by the variable first if the value held in the current element in alphas comes before the current value of first.</p></li> <li><p>The boolean condition in the line labelled //1 will evaluate to false repeatedly until i takes the value 4.</p></li> <li><p>The returned value on invoking methodA is a char array containing the values 't', 'e', 'a', 'm' and 's'.</p></li> <li><p>The returned value from invoking methodB is the character 'u'.</p></li> </ol> <p>I believe 1 to be true. Not sure why. I think 2 is false as the for loop is evaluated 6x, not 7. Not sure on 3 or 4. 5 I got to be true 6 I got to be false.</p> <p>If anyone can help I owe them a beer, a cookie and a cuddle!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload