fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] a = { 1, 3, 5 };
  13. int b = a.length - 1;
  14. // cria uma lista de int
  15. List<Integer> arr2 = new ArrayList<Integer>();
  16. int i = 0;
  17. while (i < b) {
  18. if (a[i] % 2 != 0) {
  19. // Adiciona a[i] a lista arr2
  20. arr2.add(a[i]);
  21. // Imprime o item i da lsta arr2
  22. System.out.println((int) arr2.get(i));
  23. }
  24. i++;
  25. }
  26. System.out.println(arr2); // só tem 1 e 3 (o 5 foi ignorado)
  27. }
  28. }
Success #stdin #stdout 0.03s 2249728KB
stdin
Standard input is empty
stdout
1
3
[1, 3]