I finally finished level 1 of CodingBat! But it was then when I learned about for loops that I realised that all of the level 1 probably were ridiculously easy... And I will probably say the same about Level 2 when I finish it.
After finishing Level 1, Mr. Daly explained to me what Loops were. We only really went into for loops, which was the most important and probably most common types of loops that I will work with. He explained to me that now with loops, we can go into much more advanced things and we can really mess around with an array more than before in Level 1. The array could be length 12010284, for all we know, and with the loop we would be able to find anything that CodingBat asks of us in a few short lines of code.
A lot of the time, the code will look like this, and will most likely have an if-statement inside of it.
{
for (i=0; i<nums.length; i++)
{
if ( )
{
___;
}
}
return __;
}
Of course, everything is still new to me. I think that I understand the basic of basics of how to use these loops, but I'm sure as time goes on I will get more and more familiar with them. I will be starting with Array 2 in Level 2.
Anyways. Since I just finished the easy type arrays and I also don't really know much about for loops at the moment, for this blog I'll put one last problem from Level 1:
---------------------------------------------------------------------------------------------------------------------------------
Given 2 int arrays, a and b, return a new array length 2 containing, as much as will fit, the elements from a followed by the elements from b. The arrays may be any length, including 0, but there will be 2 or more elements available between the 2 arrays. make2({4, 5}, {1, 2, 3}) → {4, 5} make2({4}, {1, 2, 3}) → {4, 1} make2({}, {1, 2}) → {1, 2} |
See you on Monday.
No comments:
Post a Comment