Taking all numbers from an arraylist and outputting only the even numbers

35 Views Asked by At

I'm fairly new to coding and I'm trying to take a users inputs and output only even numbers. This is one of a couple problems I've had with this project.

Here is the code for the button press

        int remainderEven = 0;
        for (int i = 0; i <numbers.size(); i++){
            remainderEven = numbers(i) % 2;
           
        }
        if (remainderEven == 0) {
       
        }`

My thought was that the remainder being 0 would mean that when divided by 2, the number is even. However, I'm really lost on where to continue.

Here is the code for the array as well as the button to add numbers, if that is helpful.

import java.util.*;

public class SumElementsUI extends javax.swing.JFrame {

     ArrayList <Integer> numbers = new ArrayList();

 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
      
//get the name from user input and add to "numbers" array
        int number = Integer.parseInt(numbersInput.getText());

numbers.add(number);
        outputText.setText(number + " added to the list");

//clear out the input and puts the focus back to it
        numbersInput.setText("");
        numbersInput.requestFocus();
        
    Any help is appreciated very much 
0

There are 0 best solutions below