logo
down
shadow

Java Netbeans Calculator performing wrong calculation


Java Netbeans Calculator performing wrong calculation

By : spandan s
Date : November 24 2020, 03:01 PM
like below fixes the issue I think the problems are the values of accum2 and accum2 before calculating the result. So can you check their values by using System.out.println(" accum 1 "+ accum1) and System.out.println(" accum 2 "+ accum2) before performing the computation.
code :


Share : facebook icon twitter icon
Performing a calculation in Java gives completely wrong answer

Performing a calculation in Java gives completely wrong answer


By : pragnesh
Date : March 29 2020, 07:55 AM
Any of those help The answer is not wrong, it's just not what you're expecting. You're using int division which will return an int result, a result that is truncated to the int result.
You want to do double division to get a double result, not int division which returns an int result.
code :
// the 1.0 will allow for floating point division
result = (long) (1000 * (1.0 / (x / 60)) / y); 
Java-Calculator more than one calculation

Java-Calculator more than one calculation


By : Kenny Bui
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You are having problems here because you are not careful with your if and else statements and the logic of the program. Firstly, in the actionPerformed method of ButtonOperation, you have an if(e.getActionCommand().equals("-")) inside the if(e.getActionCommand().equals("+")). That doesn't make sense, does it? The commands you are testing for with those ifs are mutually exclusive, so an else if for the - operation is what you want. Then in the ButtonAusfuehren actionPerformed() method: again, think about what you want to be doing. You don't need the last else - you can always set the result field (ergebnisFeld) to the result. Also, the operations themselves wouldn't have worked as the second time an operation was done, one of the arguments (arg1 or arg2) would have been an empty string. If you take this into account, you get something like this, which, with the other changes, makes your calculator work:
code :
        if (operation == '+')
            if (arg1.equals("")) {
                ergebnis += new Integer(arg2);
            } else {
                ergebnis = new Integer(arg1) + new Integer(arg2);
            }

        else if (operation == '-') {
            if (arg1.equals("")) {
                ergebnis -= new Integer(arg2);
            } else {
                ergebnis = new Integer(arg1) - new Integer(arg2);
            }
        }
java performing array calculation

java performing array calculation


By : Alex
Date : March 29 2020, 07:55 AM
will help you The problem is that you've not filled the board2 array, so all its elements will be 0. In the for loop, you should also assign random values to board2. You are doing it twice for the board array.
code :
//fill the grid
for (int row2 = 0; row2 < board2.length; row2++) {
    for (int col2 = 0; col2 < board2[row2].length; col2++) { // notice 'board2[row].length'
        board2[row2][col2] = rand.nextInt(10);
    }
}
//display output
for (int m = 0; m < board2.length; m++) {
    for (int n = 0; n < board2[m].length; n++) { // notice 'board2[row].length'
        System.out.print(board2[m][n] + " ");
    }
    System.out.println();
}
Performing an EC public key calculation for given secret key gives wrong results

Performing an EC public key calculation for given secret key gives wrong results


By : Christian Weißer
Date : March 29 2020, 07:55 AM
Any of those help I'm not used to Perl but i cannot see you initializing or using a cyclic group. Elliptic curve operations and asymmetric crypto in general are (mostly) always performed in a cyclic group
Java GUI calculator wont do the calculation

Java GUI calculator wont do the calculation


By : InVid San
Date : March 29 2020, 07:55 AM
Hope that helps You have confused where to put ActionListeners - they belong on components like buttons where you expect an action, and ItemListeners which belong to the check boxes. Once you sort this out your code will work. This code will update the result if you press any of the operations, or the result button.
Working code:
code :
public class Calculator extends JFrame implements ActionListener, ItemListener {

JTextField numri1, numri2;
JCheckBox shuma, diferenca, shumezimi;
JButton veprimi, ok;
JTextField rezultati;
double n1, n2;
String n1tekst, n2tekst;

public Calculator() {
    setLayout(new FlowLayout());

    numri1 = new JTextField(10);
    add(numri1);

    numri2 = new JTextField(10);
    add(numri2);

    shuma = new JCheckBox("Shuma");
    add(shuma);
    shuma.addItemListener(this);

    diferenca = new JCheckBox("Diferenca");
    add(diferenca);
    diferenca.addItemListener(this);

    shumezimi = new JCheckBox("Shumezimi");
    add(shumezimi);
    shumezimi.addItemListener(this);

    veprimi = new JButton("Kryej Veprimin");
    add(veprimi);
    veprimi.addActionListener(this);

    rezultati = new JTextField(10);
    add(rezultati);

    ok = new JButton("OK");
    add(ok);

}

public void itemStateChanged(ItemEvent e) {
    n1 = Double.parseDouble(numri1.getText());
    n2 = Double.parseDouble(numri2.getText());
    if (e.getSource() == shuma) {
        String rez = shuma.isSelected() ? "" + (n1 + n2) : "";
        rezultati.setText(rez);
    } else if (e.getSource() == diferenca) {
        String rez = diferenca.isSelected() ? "" + (n1 - n2) : "";
        rezultati.setText(rez);
    } else if (e.getSource() == shumezimi) {
        String rez = shumezimi.isSelected() ? "" + (n1 * n2) : "";
        rezultati.setText(rez);
    }
}

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == veprimi) {
        n1 = Double.parseDouble(numri1.getText());
        n2 = Double.parseDouble(numri2.getText());
        if (shuma.isSelected()) {
            rezultati.setText("" + (n1 + n2));
        } else if (diferenca.isSelected()) {
            rezultati.setText("" + (n1 - n2));
        } else if (shumezimi.isSelected()) {
            rezultati.setText("" + (n1 * n2));
        }
    }
}

public static void main(String args[])

{
    Calculator ob = new Calculator();
    ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ob.setSize(900, 900);
    ob.setVisible(true);
}

}
public class Ngjyra extends JFrame implements ActionListener {

JCheckBox kuqe, blu;
JButton veprimi, ok;

public Ngjyra() {
    setLayout(new FlowLayout());
    kuqe = new JCheckBox("Kuqe");
    add(kuqe);
    blu = new JCheckBox("Blu");
    add(blu);

    veprimi = new JButton("Kryej Veprimin");
    add(veprimi);
    veprimi.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == veprimi) {
        if (kuqe.isSelected()) {
            this.getContentPane().setBackground(Color.RED);
        } else if (blu.isSelected()) {
            this.getContentPane().setBackground(Color.BLUE);
        }
    }

}

public static void main(String args[])

{
    Ngjyra ob = new Ngjyra();
    ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ob.setSize(900, 900);
    ob.setVisible(true);
}
}
shadow
Privacy Policy - Terms - Contact Us © voile276.org