« All Events
2:30 PM – Intro To Competitive Programming – Gamas
September 16, 2023 @ 2:30 pm - 3:30 pm
Homework
- Create Sep16ArrayHomework.java
- Create a new int array(6) (“numbers”) and add the following values: -100,2,3,100,-5,14
- Create a new int array(20) (“bigCapacityNumbers”) and use for loop to copy all elements from “numbers” to “bigCapacityNumbers”
- Add code to count how many negative numbers inside the “numbers” array. Hint: you have to use for loop and if statement.
- Study this modulus operator – https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/what-is-modular-arithmetic
- Modulus (%) is an operator that is supposed to give you a reminder of a division. Copy below codes and run it
-
class ModulusOperator {
public static void main(String[] args) {
int num1, num2, result;
num1 = 26;
num2 = 15;
System.out.println("num1=26; num2=15");
result = num1 % num2;
System.out.println("The result after modulus operation is : " + result);
}
}
- After you learn how to use modulus in Java, write a code that will go through each element inside “numbers” and print all odd number inside the list using modulus (%) operator.