Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I disagree with alphazero. I don't think two variables are REQUIRED. every number is either ever or odd. So keeping count of one is enough.</p> <p>As for Asaph's code, I think it is well documented, but if you still want an explanation, here goes:</p> <p>This is what the for loop does:</p> <p>It reads (as Strings) user input for the 3 numbers<br> <code>Integer.parseInt</code> is a function that takes a <code>String</code> as a parameter (for example, <code>'4'</code>) and returns an <code>int</code> (in this example, <code>4</code>). He then checks if this integer is even by modding it by 2. The basic idea is: 4%2 = 0 and 9%2 = 1 (the mod operator when used as <code>a%b</code> gives the remainder after the operation <code>a/b</code>. Therefore if <code>a%2</code> is 0, then a is even). There is a counter (called <code>evenCount</code>) that keeps track of how many integers are even (based on the <code>%s</code> test).</p> <p>He then proceeds to do switch statement on the <code>evenCount</code>. A switch statement is sort of like an if-else statement. The way it works is by testing the switch parameter (in this case, <code>evenCount</code>) against the case values (in this case, 3, 2, 1, 0). If the test returns True, then the code in the case block is executed. If there is no break statement at the end of that case block, then, the code in the following case block is also executed.</p> <p>Here, Asaph is checking to see how many numbers are even by comparing the evenCount to 0, 1, 2, and 3, and then usinga appropriate print statements to tell the user how many even numbers there are</p> <p>Hope this helps</p>
    singulars
    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.
    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