Java Code To Find The Sum OF The Series


Java Code To Find The Sum OF The Series
===============================

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        int a, n, d = 0, ans;
        a = Integer.parseInt(tf1.getText());
        n = Integer.parseInt(tf2.getText());



        switch (cb1.getSelectedIndex()) {
            case 0:
                d = 1;
                break;
            case 1:
                d = 2;
                break;
            case 2:
                d = 3;
                break;
            case 3:
                d = 4;
                break;
            default:JOptionPane.showMessageDialog(this,"Select some thing ");
                break;

        }
        ans = (n / 2 )* (2 * a + (n - 1) * d);
        lb1.setText("" + ans);


        // TODO add your handling code here:
    } 

No comments:

Post a Comment