abcFormel Rechner. (nicht fertig)
parent
a47837e2ca
commit
de04b108d6
|
@ -0,0 +1,68 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class abcRechner
|
||||||
|
{
|
||||||
|
public static void abcrechenr()
|
||||||
|
{
|
||||||
|
//screen display
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println("Input first number");
|
||||||
|
double a = sc.nextInt();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Input second number");
|
||||||
|
double b = sc.nextInt();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Input thinrd number");
|
||||||
|
double c = sc.nextInt();
|
||||||
|
|
||||||
|
|
||||||
|
//program start
|
||||||
|
|
||||||
|
double root;
|
||||||
|
root = Math.sqrt((b * b) - (4 * a * c));
|
||||||
|
|
||||||
|
double bottom;
|
||||||
|
bottom = 2 * a;
|
||||||
|
|
||||||
|
double result1;
|
||||||
|
result1 = (-b + root) / bottom;
|
||||||
|
|
||||||
|
double result2;
|
||||||
|
result2 = (-b - root) / bottom;
|
||||||
|
|
||||||
|
//outputs
|
||||||
|
|
||||||
|
if( root < 0) {
|
||||||
|
|
||||||
|
System.out.print("no answer possible");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
if( root == 0) {
|
||||||
|
|
||||||
|
System.out.print("The answer is: ");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
System.out.print("first answer is: ");
|
||||||
|
System.out.println(result1);
|
||||||
|
|
||||||
|
System.out.print("second answer is: ");
|
||||||
|
System.out.println(result2);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue