Crenox

Enhanced For Loop with String

May 15th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 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. String myarray[] = {"sam", "rommy", "zack"};
  8.  
  9. for (String i: myarray)
  10. {
  11. if(i == myarray[2])
  12. {
  13. System.out.println(i);
  14. }
  15. else
  16. {
  17. System.out.print(i + ", ");
  18. }
  19. }
  20. }
  21. }
  22. // Output: sam, rommy, zack
Advertisement
Add Comment
Please, Sign In to add comment