Results 1 to 5 of 5
Thread: Basic Netbeans question
- 02-19-2009, 04:18 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 47
- Rep Power
- 0
Basic Netbeans question
I need to put the Math package into this.
Java Code:package javaapplication2; import java.lang.Math; /** * * @author Sterling */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { double x = 23.45; double ans; ans = sqrt(x); System.out.println("The square root of 23.45 is " + ans); } }
That is what I have so far. It keeps telling me sqrt is not found and java.lang.Math is an unused import. Am I just putting the import in the wrong place? I'm really new to Netbeans also.
- 02-20-2009, 12:41 AM #2
1. java.lang.Math is an unecessary import because it is automatically imported into every class, you don't need to import it so get rid of that statement.
2. The error is you have to type Math.sqrt (if sqrt is a static method), not just sqrt. To be able to leave out the Math., you would have to do "import static java.lang.Math;", but this should only be used when there are many references to static Math methods. As stated in the API, use static imports very sparingly, you would need many references to static Math methods to justify using a static import. So the solution, use Math.sqrt(x);, and get rid of the import. Hope this helped.
-MK12Last edited by MK12; 02-20-2009 at 12:43 AM. Reason: adding
Tell me if you want a cool Java logo avatar like mine and I'll make you one.
- 02-20-2009, 02:16 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Well said MK12, actually this is nothing to do with NetBeans. This is all about Java basis. Seems our thread starter McChill is a newbie to Java. Did you referring any materials about Java?
- 02-20-2009, 04:16 PM #4
Thanks to MK12.
Mak
(Living @ Virtual World)
- 02-20-2009, 10:22 PM #5
Similar Threads
-
Basic question on OOP.
By madthinker in forum New To JavaReplies: 7Last Post: 01-26-2009, 07:09 PM -
Basic MouseListener Question
By jshailes in forum AWT / SwingReplies: 9Last Post: 01-15-2009, 08:58 AM -
Basic question about EJB
By javaplus in forum Enterprise JavaBeans (EJB)Replies: 2Last Post: 07-15-2008, 05:44 PM -
Basic different between netbeans and eclipse
By shu2hua in forum New To JavaReplies: 9Last Post: 05-29-2008, 10:34 AM -
Very basic question
By gvi in forum New To JavaReplies: 2Last Post: 10-30-2007, 06:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks