Skip to editor
File
New File Ctrl+N
New Folder

Save Ctrl+S
Upload File…
Download as ZIP

Delete File

Reset Files…
View
Toggle Sidebar Ctrl+B
Toggle Terminal Ctrl+`

Word Wrap Alt+Z

Exercise Info
Run
Run Code Ctrl+Enter
Save & Run F5

Clear Output
CS173: Intro to Computer Science - Functions (3 pts)
Explorer
GitHub

Connect to GitHub to push and pull your project files to a repository.

On the page that opens, create a token with repo scope, copy it, then paste it below.

Paste the personal access token you created on GitHub with repo scope.

Click Refresh to load commit history
Exercise Info

Goals

  1. To write mathematical expressions in Java
  2. To write a function that computes an expression and returns its result
  3. To call a function from main() and use its return value

Instructions

Write a function that computes one of the roots of a quadratic equation. In addition to multiplying b by itself, you can compute b*b using the Math.pow() method. The Math.sqrt() method takes a double parameter, which is the number whose root should be computed, and returns the result as a double. Now write a program that calls a method that you will write to compute the quadratic root, and then have main() print the root that you calculate.

Quadratic Formula

For reference, the quadratic formula is:

\[\frac{-b \pm \sqrt{(b^{2} - 4ac)}}{2a}\]

given an equation:

\[ax^{2} + bx + c = 0\]

In this exercise, you can simply compute one of the roots, as follows:

\[\frac{-b + \sqrt{(b^{2} - 4ac)}}{2a}\]


The Ursinus-WebIDE by Chris Tralie (opens in new tab) and Bill Mongan (opens in new tab)

Your browser does not support WebGL. A graphical rendering canvas would appear here.


          
No suggestions. Code quality feedback will appear here.
Not logged in java
Ln 1, Col 1