Created
November 1, 2011 01:18
-
-
Save NatashaTheRobot/1329584 to your computer and use it in GitHub Desktop.
This is the solution to the Pythagorean Theorem problem from Assignment 2 of the Stanford CS106A Introduction to Programming Methodology Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* File: PythagoreanTheorem.java | |
* Name: | |
* Section Leader: | |
* ----------------------------- | |
* This file is the starter file for the PythagoreanTheorem problem. | |
*/ | |
import acm.program.*; | |
public class PythagoreanTheorem extends ConsoleProgram { | |
public void run() { | |
sayWelcomeMessage(); | |
askUserInput(); | |
} | |
private void sayWelcomeMessage() { | |
println( "Enter values to compute the Pythagorian theorem" ); | |
} | |
private void askUserInput() { | |
int a = readInt ("a:"); //asks user to enter an integer for a | |
int b = readInt ("b:"); //asks user to enter an integer for b | |
double x = (double)a; // converts variable "a" from an integer to a double | |
double c = Math.sqrt((x*x) + (b*b)); //calculates square root | |
println("c:"+ c); //displays value as a double | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment