0

Hi All
Kindly assist am having issue with the following code, where did i get it wrong? Only the first Block condition is execute, even if B<PA, the second block does not execute. Am using Netbean

        PA =((1.1 * P2) / (1.46 * P3));

        B = 3 * P4;
        D = P4;

        B1 = PA + 0.02;
        D1 = ((B - P4) / 2);

        if (B > PA) {
            txtB.setText("" + Round(B,2));
            txtD.setText("" + Round(D,2));
            patxt.setText(""+ PA);
        }
        else {
            txtB.setText("" + Round(B1,2));
            txtD.setText("" + Round(D1,2));
            patxt.setText(""+ PA);
        }

Edited by JamesCherrill: No need to shout (lower case is better for titles)

3
Contributors
5
Replies
31
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

I don't see anywhere that you have set vales for P2, P3 or P4 so don't see how you expect this to work

0

It's highly unlikely that you have found a bug in Java's execution of if tests, so try a little debugging to confirm what's happening. Print B and PA immediately before the if test, put one print statement in the if, one in the else to confirm what is or isn't being executed.

Edited by JamesCherrill

0

Am using netbeans, so P2, P3 or P4 are actual the inputs(double variable): I actually just cut of the Conditional Statement :
This the lenthy Code: though still reduced:
String m = pcTxt.getText();

    P2 = Double.parseDouble(n);
    String o = pbTxt.getText();
    P3 = Double.parseDouble(o);
    String p = tTxt.getText();
    P4 = Double.parseDouble(p);


    PA =((1.1 * P2) / (1.46 * P3));
    B = 3 * P4;
    D = P4;

    B1 = PA + 0.02;
    D1 = ((B - P4) / 2);

    if (B > PA) {
        txtB.setText("" + Round(B,2));
        txtD.setText("" + Round(D,2));
        //patxt.setText(""+ PA);
    }
    else {
        txtB.setText("" + Round(B1,2));
        txtD.setText("" + Round(D1,2));
        //patxt.setText(""+ PA);
    }
0

the output is to be displayed in txtB and txtD which are jTextFields, the first condition works just fine, but d second doesn't

0

... try a little debugging to confirm what's happening. Print B and PA immediately before the if test, put one print statement in the if, one in the else to confirm what is or isn't being executed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.