Download Honors04

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Honors Section, Lecture #1 - Fall 04
First project:
The Cube Sum Problem
Find all of the 3 digit numbers (integers) that equal the sum of the cubes
of their digits.
Example - 153 = 1*1*1 + 5*5*5 + 3*3*3
Find the others!!!!
Do this with 2 classes (e.g. a CubeSum, and CubeSumTester class)
Put “main” in the second class
% - the remainder operation: 17 % 4 = 1
/ - two integers rounds down: 17 / 4 = 4
Numerical equality: ==
(e.g. if (k % 2 == 1) then System.out.println(k + “ “ + “ is odd”);
Think “generate and test”:
Cycle through the numbers for 100 to 999
For each, calculate its cubesum, and see if you get the same number back
for(int k = 1; k < 6; k++)
System.out.println(k);
Prints:
1
2
3
4
5
How would you print the numbers 100 - 999 in a column?
methods and headers…
public int cubeSum(int k){
Blah, blah
return (..some int..)
}
public boolean dividesEvenly(int a, int b){ //does a go into b evenly?
if (b % a == 0) return true else return false;
}
OR
return (b % a == 0);
Also: the form of my solution..
Related documents