Skip to content

Instantly share code, notes, and snippets.

@NatashaTheRobot
Created November 1, 2011 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NatashaTheRobot/1329584 to your computer and use it in GitHub Desktop.
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
/*
* 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