Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

New to Java Need Help


  • This topic is locked This topic is locked

#1
MkLoe

MkLoe

    Visiting Staff

  • Member
  • PipPipPip
  • 650 posts
I am new to java and need some help with the quadratic formula here is what I have:


import javax.swing.JOptionPane;

public class Math {

public static void main (String args[]) {

String strA;
String strB;
String strC;

//allows decimals
double dblA, dblB, dblC, dblAnswerOne, dblAnswerTwo, dblM, dblP, dblY, dblX, dblZ;

//This asks what you want to be entered
strA = JOptionPane.showInputDialog("Enter A");
strB = JOptionPane.showInputDialog("Enter B");
strC = JOptionPane.showInputDialog("Enter C");


//This tell java to convert words into number
dblA = Double.parseDouble(strA);
dblB = Double.parseDouble(strB);
dblC = Double.parseDouble(strC);

//Performs Operation
dblM = (dblB * dblB) - (4 * dblA * dblC);
dblP = (- (dblB)) + (Math.sqrt(dblM) );
dblAnswerOne = (dblP / (2 * dblA));


//will have answer Two soon but want to get one down first
JOptionPane.showMessageDialog(null,"X =" + dblAnswerOne);

System.exit(0);


}

}


Here is my compiler :

C:\Documents and Settings\Michael\Desktop\Math.java:28: cannot find symbol
symbol : method sqrt(double)
location: class Math
dblP = (- (dblB)) + (Math.sqrt(dblM) );
^
C:\Documents and Settings\Michael\Desktop\Math.java:28: operator + cannot be applied to double,Math.sqrt
dblP = (- (dblB)) + (Math.sqrt(dblM) );
^
C:\Documents and Settings\Michael\Desktop\Math.java:28: incompatible types
found : <nulltype>
required: double
dblP = (- (dblB)) + (Math.sqrt(dblM) );
^
3 errors

Tool completed with exit code 1

Any help is appreciated
  • 0

Advertisements


#2
MkLoe

MkLoe

    Visiting Staff

  • Topic Starter
  • Member
  • PipPipPip
  • 650 posts
I got it anyone intrested here it is:

//Created by MkLoe
//May 1, 2007


import javax.swing.JOptionPane;
import java.lang.Math;

public class Quadratic {

public static void main (String args[]) {

String strA;
String strB;
String strC;

//allows decimals
double dblA, dblB, dblC, dblAnswerOne, dblAnswerTwo, dblM, dblP, dblY, dblX;

//This asks what you want to be entered
strA = JOptionPane.showInputDialog("Enter A");
strB = JOptionPane.showInputDialog("Enter B");
strC = JOptionPane.showInputDialog("Enter C");


//This tell java to convert words into number
dblA = Double.parseDouble(strA);
dblB = Double.parseDouble(strB);
dblC = Double.parseDouble(strC);

//Performs Operation
//Answer One
dblM = (dblB * dblB) - (4 * dblA * dblC);
dblP = (- (dblB)) + (Math.sqrt(dblM) );
dblAnswerOne = (dblP / (2 * dblA));

//Answer Two
dblY = (dblB * dblB) - (4 * dblA * dblC);
dblX = (- (dblB)) - (Math.sqrt(dblY) );
dblAnswerTwo = (dblX / (2 * dblA));


JOptionPane.showMessageDialog(null,"X =" + dblAnswerOne);
JOptionPane.showMessageDialog(null,"or X =" + dblAnswerTwo);

System.exit(0);


}

}


Edited by MkLoe, 01 May 2007 - 07:15 PM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP