 # Stanford CS106A Assignment 2 Pythagorean Theorem Solution

Woohooo! Finally an easier one 🙂 This one, the professor pretty much went over in Lecture 6. Luckily, I took good notes. Here is the problem: Here is my solution, also available on github:

Since the other problems here were Graphics programs, I stumbled a bit by creating a “GLabel”. Since this is a Console program, remember to use “println()” to display a message or “readInt()” stored as an integer to ask the user for feedback. If you keep these in mind, this is a pretty simple problem (probably the easiest one in Assignment 2).

```&lt;pre&gt;/*
* 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( &quot;Enter values to compute the Pythagorian theorem&quot; );
}
private void askUserInput() {
int a = readInt (&quot;a:&quot;); //asks user to enter an integer for a
int b = readInt (&quot;b:&quot;); //asks user to enter an integer for b
double x = (double)a; // converts variable &quot;a&quot; from an integer to a double
double c = Math.sqrt((x*x) + (b*b)); //calculates square root
println(&quot;c:&quot;+ c); //displays value as a double
}
}&lt;/pre&gt;
```

Enjoy the article? Join over 20,000+ Swift developers and enthusiasts who get my weekly updates.