Created
September 12, 2016 16:30
-
-
Save joakiti/db2015c7e318ac8f6f9b181d68f9956c to your computer and use it in GitHub Desktop.
Opgave GA.2
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
// Hej, hvordan får jeg min kode til at returnere ciffrene uden at skifte linje? | |
public class Quadratic{ | |
// Opgave i | |
private double a; | |
private double b; | |
private double c; | |
private double x; | |
private double d; | |
public Quadratic(double a, double b, double c) { | |
this.a = a; | |
this.b = b; | |
this.c = c; | |
d = b*b-4*a*c; | |
} | |
// Opgave ii | |
public void show() { | |
System.out.println(a + "x*x + " + b + "x +" + c); | |
} | |
// Opgave iii | |
public double compute(double x) { | |
return a*x*x+b*x+c; | |
} | |
public void solve() { | |
double firstResult = ((-b + Math.sqrt(d)) / (2*a)); | |
double secondResult = ((-b - Math.sqrt(d)) / (2*a)); | |
if ( d == 0) { | |
System.out.println("Der findes 1 løsning til andengradsligningen"); | |
System.out.println("Løsning til andengradlingnen er: " + String.format("%.2g%n",firstResult)); | |
} | |
if ( d < 0) { | |
System.out.println("Der findes ikke en løsning til andengradsligningen"); | |
} | |
if ( d > 0) { | |
System.out.println("Der findes 2 løsninger til andengradsligningen"); | |
System.out.println("Løsningerne til andengradligningen er: " + String.format("%.2g%n",firstResult) + " og " + String.format("%.5g%n",secondResult)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
linje 30 System.out.println("Der findes 1 løsning til andengradsligningen"); --> System.out.print("Der findes 1 løsning til andengradsligningen");