I might actually be able to come up with an example where it would be used; the '=='
You guys have been very helpful.
I was wondering if someone can point me in the direction of what i should be looking into when I want to used complex numbers?
Here's an obviously wrong code for it i have so far.
double sqrt = (Math.sqrt(Math.pow(b, 2) - 4*a*c));
//System.out.println("We should then take the square root of ((b^2) - 4ac): " + sqrt);
//if (sqrt < 0) {
// Math.abs(Math.sqrt(Math.pow(b, 2) - 4*a*c));
//}
if (sqrt < 0) {
System.out.println("You have entered an equation with one or more complex numbers. i = the sqare root of -1");
double numImaginary = (sqrt * Math.pow(1, -2));
System.out.println("We should then take the square root of ((b^2) - 4ac)= " + sqrt + "i");
}
else {
System.out.println("We should then take the square root of ((b^2) - 4ac)= " + sqrt);
}
FULL CODE
import java.util.Scanner;
public class calc_Quadratic {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String reply = null;
String hint = null;
double a = 0;
double b = 0;
double c = 0;
System.out.println("Welcome to the homemade Quadratic Formula Calculator.");
System.out.println("");
System.out.println("This program will help you find the possible zeroes in your specific equations.");
System.out.println("The quadratic formula is as follows -- ((ax^2) + bx + c)/2a");
System.out.println("If your equation is in the said formula, please continue and fill out the following variables with their corresponding numbers.");
System.out.println("");
System.out.println("");
System.out.println("(ax^2) [otherwise known as a x squared]: ");
a = keyboard.nextInt();
System.out.println("");
System.out.println("bx: ");
b = keyboard.nextInt();
System.out.println("");
System.out.println("c: ");
c = keyboard.nextInt();
System.out.println("");
System.out.println("");
System.out.println("Are you ready for the next step?");
reply = keyboard.next();
while (!reply.equalsIgnoreCase("yes")) {
System.out.println("Please type in 'yes' when you are ready.");
reply = keyboard.next();
}
System.out.println("First we must take the opposite of b (positive/negative): " + -b);
double oppositeB = -b;
System.out.println("");
System.out.println("Are you ready for the next step?");
reply = keyboard.next();
while (!reply.equalsIgnoreCase("yes")) {
System.out.println("Please type in 'yes' when you are ready.");
reply = keyboard.next();
}
double sqrt = (Math.sqrt(Math.pow(b, 2) - 4*a*c));
//System.out.println("We should then take the square root of ((b^2) - 4ac): " + sqrt);
//if (sqrt < 0) {
// Math.abs(Math.sqrt(Math.pow(b, 2) - 4*a*c));
//}
if (sqrt < 0) {
System.out.println("You have entered an equation with one or more complex numbers. i = the sqare root of -1");
double numImaginary = (sqrt * Math.pow(1, -2));
System.out.println("We should then take the square root of ((b^2) - 4ac)= " + sqrt + "i");
}
else {
System.out.println("We should then take the square root of ((b^2) - 4ac)= " + sqrt);
}
System.out.println("");
System.out.println("Are you ready for the next step?");
reply = keyboard.next();
while (!reply.equalsIgnoreCase("yes")) {
System.out.println("Please type in 'yes' when you are ready.");
reply = keyboard.next();
}
//...
double addTop = oppositeB + sqrt;
double minusTop = oppositeB - sqrt;
//...
System.out.println("Now we will have to add our result of the first step: " + oppositeB + ", to our result from the second step: " + sqrt + ", to get: " + addTop);
System.out.println("We will then have to replace the addition sign to subtract our second result, " + sqrt + ", from our 1st result, " + oppositeB + ", to get: " + minusTop);
System.out.println("");
System.out.println("Are you ready for the next step?");
reply = keyboard.next();
while (!reply.equalsIgnoreCase("yes")) {
System.out.println("Please type in 'yes' when you are ready.");
reply = keyboard.next();
}
//...
double divPositive = addTop/(2*a);
double divNegative = minusTop/(2*a);
//...
System.out.println("Alright. Next we will have to divide 2a (2 * a), " + (2 * a) + ", from the result of step 3, " + addTop + ", to get: x = " + divPositive);
System.out.println("Finally we will have to divide 2a (2 * a), " + (2 * a) + ", from the result of step 4, " + minusTop + ", to get: x= " + divNegative);
System.out.println("");
System.out.println("");
if (divPositive == divNegative) {
System.out.println("You only have one zero. It is: x = " + divPositive);
}else {
System.out.println( "Your zeroes are: x = " + divPositive + " and x = " + divNegative);
}
//Must add conditional statement for imaginary numbers
//Must add conditional statements if both x's = each other done~
//Add statement if only one zero
//Possibly edit program to have user enter correct answer in order to continue*