+ 2

Java help

import java.util.ArrayDeque; import java.util.Deque; public class ArrayDequeExample { public static void main(String[] args) { Deque<Integer> d = new ArrayDeque<Integer>(); d.add(10); d.add(31); d.add(26); d.add(13); d.add(17); d.add(4); d.add(7); System.out.println(d); System.out.println("Even integers"); } } What should I do so that only even integers appear please?

9th Apr 2022, 7:27 AM
Daniel Alexis
8 odpowiedzi
+ 2
for(int i:d){ if(i % 2 ==0){ System.out.println(i); }} this prints only the even numbers if that's what you want
9th Apr 2022, 7:40 AM
celeb17
celeb17 - avatar
+ 1
import java.util.ArrayDeque; import java.util.Deque; public class ArrayDequeExample { public static void main(String[] args) { Deque<Integer> d = new ArrayDeque<Integer>(); d.add(10); d.add(31); d.add(26); d.add(13); d.add(17); d.add(4); d.add(7); for(int i:d){ if(i % 2 ==0){ System.out.println(i); } }
9th Apr 2022, 8:36 AM
Daniel Alexis
0
Thx
9th Apr 2022, 8:28 AM
Daniel Alexis
0
Would seem that there is an error it does not work
9th Apr 2022, 8:36 AM
Daniel Alexis
0
add two curly braces add the end these }}
9th Apr 2022, 8:40 AM
celeb17
celeb17 - avatar
0
My goal is to create a queue with integers and have only even integers displayed
9th Apr 2022, 8:43 AM
Daniel Alexis
0
Thx
9th Apr 2022, 8:50 AM
Daniel Alexis
0
anyone help to learn Java
17th Apr 2022, 12:44 AM
B. Rajesh
B. Rajesh - avatar