Assignment – For Loops

advertisement
ICS3U1 – Unit 1
Intro to Programming
Name: _______________
Assignment – For Loops
due midnight on Wednesday, February 25th
Instructions: Create a new Java Project in Eclipse called Assignment Two.
Write each program using the name indicated in the problem (1 mark COMM each).
Make sure that your code is fully documented with an appropriate header containing your
name, date, and what the program does (1 mark COMM each). Be sure to include
documentation throughout your program.
Upon completion, upload your java files to the shared Google Drive into a folder called
Assignment – For Loops.
Application:
/11
Thinking, Inquiry & Problem Solving:
1. Write a program that outputs the first thirty multiples of 3.
Save your program as ThirtyMultiples.java.
/10
(2 marks APP)
2. Write a program that asks the user for an integer. Your program should output the
1 to 12 times table for that integer using a for loop.
Save your program as TimesTableLoop.java.
(3 marks APP)
3. Write a program that asks the user for a positive integer. Your program will output
all of the positive divisors of that integer.
Note: A divisor of a number N is a number that divides evenly into N.
Save your program as Divisors.java.
(3 marks APP)
4. Write a program that asks the user for a positive integer. Your program should
output all of the prime numbers between 2 and the given number.
Hint: Think about how you will do this before you start programming. If you get
stuck, bring your thoughts to me and we’ll talk about a strategy. You will need to
use a nested loop for this program!
(3 marks APP)
Save your program as Primes.java.
(2 marks TIPS)
5. (Challenge problem) A pair of integers m and n are called amicable if the divisors
of m add up to n and vice versa. Write a program that finds all of the amicable
numbers between 1 and 10,000.
Save your program as Amicable.java.
(2 marks APP)
(2 marks TIPS)
Download