Crenox

Enhanced For Loop with ints

May 15th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. package com.samkough.java.main;
  2.  
  3. public class Integers
  4. {
  5. public static void main(String[] args)
  6. {
  7. int myarray[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
  8.  
  9. for (int i: myarray)
  10. {
  11. if(i == myarray[10])
  12. {
  13. System.out.println(i);
  14. }
  15. else
  16. {
  17. System.out.print(i + ", ");
  18.  
  19. }
  20. }
  21. }
  22. }
  23.  
  24. // Output: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29
Advertisement
Add Comment
Please, Sign In to add comment