Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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