View Single Post
ישן 05-10-06, 23:54   # 6
Balrog
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
הודעות: 121

Balrog לא מחובר  

טוב שוב אני חוזר
עכשיו ברור לי מה אמור לעשות JOptionPane, אבל שמתי לב גם שהבעיה היא בקטע שלו.
אני עדיין לא יודע למה - אולי בהמשך.

לגבי התוכנית עצמה - לא הבנתי מה ניסית לעשות שם, אני זוכר את נוסחאת השורשים קצת אחרת, בצורה הבאה:
קוד:
import java.lang.Math;
import javax.swing.JOptionPane;

public class hello {

    public static void main() {

        int a,b,c,m,f,f2,g;

        /*
        a = Integer.parseInt(JOptionPane.showInputDialog("insert first number"));
        b = Integer.parseInt(JOptionPane.showInputDialog("insert sec number"));
        c = Integer.parseInt(JOptionPane.showInputDialog("insert third number"));
*/
    
       a=1;
       b=-4;
       c=4;

        m = b*b - 4*a*c;

        if (m > 0)
        {
            g = (int)Math.sqrt((double)m);
            f = (-b + g)/(2*a) ;
            f2 = (-b - g)/(2*a);
            System.out.println("the first result is: " + f);
            System.out.println("the sec result is: " + f2);
        }
        else if (m == 0)
        {
            g = (int)Math.sqrt((double)m);
            f = -b/(2*a) ;
            System.out.println("the only result is: " + f);
        }
        else
        {
            System.out.print("Error: No Results.");   
        }
    }

}