+ 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?
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
+ 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);
}
}
0
Thx
0
Would seem that there is an error it does not work
0
add two curly braces add the end
these }}
0
My goal is to create a queue with integers and have only even integers displayed
0
Thx
0
anyone help to learn Java