Euler Project 1 Solution
Ahh, yes. Good ol’ Project Euler. Here’s my solution:
[cc lang=“java”]
import java.util.Scanner;
//Program to solve Euler Project One
//kuemerle5
//Block 2
public class euler1{
private int inputNum;
private int factorOne;
private int factorTwo;
private int numSum;
//This method simply gets the user’s input
public void getInfo(){
Scanner in = new Scanner(System.in);
System.out.print(“Please enter the number you wish me to find the sum of two numbers: ”);
inputNum = in.nextInt();
System.out.print(“Please enter the first multiple: ”);
factorOne = in.nextInt();
System.out.print(“Please enter the second multiple: ”);
factorTwo = in.nextInt();
System.out.println(“Thank you for your input. We will now do some calculations. Stand by…”);
}
//This is the main part of the program, using a “for” statement, then a nested “if” statement
public void doWork(){
for(int runAmt=1; runAmt<inputNum; runAmt+=1){
if(runAmt%factorOne==0 || runAmt%factorTwo==0){
numSum += runAmt;
}
}
}
//The “getOutput” method prints out the results of the “doWork” method
public void getOutput(){
System.out.println(“Sum is: ” + numSum);
}
}
[/cc]
| Print article | This entry was posted by Owen Kuemerle on January 12, 2009 at 11:48 am, and is filed under AP Computer Science. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

about 1 year ago
YOU’RE LATE…
GRR!
about 1 year ago
I DEMAND A NEW BLOG POST!!!!!!!!!!
(and so does patrick as well)
about 1 year ago
Hang on a second here…is this really a post?
I have no clue what the heck this is. But it appears you may actually have content for the first time!!