CS61B HW0

时间:2021-08-17 13:27:44

The Enhanced For Loop

public class EnhancedForBreakDemo {
public static void main(String[] args) {
String[] a = {"cat", "dog", "laser horse", "ketchup", "horse", "horbse"}; for (String s : a) {
for (int j = 0; j < 3; j += 1) {
System.out.println(s);
if (s.contains("horse")) {
break;
}
}
}
}
}

here "String s : a" is equal to for i loop and use s to replace a[i]

相关文章