Results 1 to 3 of 3
  1. #1
    Pinokio1993 is offline Member
    Join Date
    May 2013
    Location
    Belgium
    Posts
    2
    Rep Power
    0

    Default problem with a math program

    I'm testing java for two days and I'm using this site [URL="http://introcs.cs.princeton.edu/java/10elements/"]
    I tried to combine the Quadratic and the TenHellos program,
    but if I run the program it gives a lot of printlines and I can't stopping them.
    Can somebody help me plz, I write it in Notebook.

    Java Code:
    public class Quadratic {
    	public static void main(String[] args) {
    
    	// vergelijking oplossen
    		double a = Double.parseDouble (args [0]);
    		double b = Double.parseDouble (args [1]);
    		double c = Double.parseDouble (args [2]);
    
    		double D = b*b - 4*a*c;
    		double sqroot = Math.sqrt (D);
    
    		double root1 = (-b + sqroot) / 2;
    		double root2 = (-b - sqroot) / 2;
    
    	// uitkomsten weergeven
    
    
    		while (D < 0)
    		System.out.println ("error");
    		
    		while (D >= 0)
    		System.out.println ("X1=" + root1 + "en X2=" + root2);
    
    
    
    }}
    I'm sorry if my English is not that good...
    Last edited by JosAH; 05-11-2013 at 08:59 PM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: problem with a math program

    Change those 'while (D ...)' into 'if (D ...)'.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Pinokio1993 is offline Member
    Join Date
    May 2013
    Location
    Belgium
    Posts
    2
    Rep Power
    0

    Default Re: problem with a math program

    tnx, the program is working!

Similar Threads

  1. Replies: 2
    Last Post: 10-27-2011, 10:06 PM
  2. Need help ASAP on a math program
    By Swiper in forum New To Java
    Replies: 11
    Last Post: 08-13-2011, 07:16 AM
  3. help w/ PI Math java program
    By clemsontigers in forum New To Java
    Replies: 12
    Last Post: 02-17-2011, 08:18 AM
  4. Math Program
    By stlboi in forum New To Java
    Replies: 8
    Last Post: 04-02-2009, 10:34 PM
  5. need help with math for a new program
    By gotenks05 in forum New To Java
    Replies: 13
    Last Post: 09-26-2008, 08:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •