Wednesday, February 25, 2015

Wednesday, February 25th

Regular class today.

I am slowly getting the hang of the new concept of for loops. I am learning how to use them but still am not used to them completely. Since I don't really have a lot to say, I'll get straight to the problem of the day:

Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count. 

sum13({1, 2, 2, 1}) → 6
sum13({1, 1}) → 2
sum13({1, 2, 2, 1, 13}) → 6

------------------------------------------------------------------------------------------------------------

public int sum13(int[] nums) {
 
  int sum = 0;
//define the sum as an int starting as 0.
 
  for (int i=0; i<nums.length; i++)
// write the loop
  {
    if (!(nums[i]==13))
// if an element doesn't equal 13
    {
      sum=sum+nums[i];
// then keep on adding to the sum;
    }
   
    else
    {
     i++;
//if it does equal 13, then don't add anything to the sum and skip 2 elements, because we want to skip
// 13 and the number that comes after it.
    }
   
  }
  return sum;
// return the sum of all the ints, besides the exception of 13 and the number that follows it.
 }
----------------------------------------------------------------------------------------------------------------------------------

On Friday, we won't be having a regular class. Since it's library technology week, we are going up to the library and working there. Mei and I will be sort of "touring around" the middle schoolers that are coming to visit and we will be taking them around the library, introducing them to everybody who will also explain what they are working on. Basically, we will give them a little taste of what we do in class and how it works, and what are the things that people do. Looking forward to it!

No comments:

Post a Comment