- /*
- * 是这个意思吗?
- */
- public class Question {
- public static void main(String[] args) {
- String[] strArr = { "赤", "橙", "红", "绿", "青", "蓝", "紫" };
- System.out.println("while方法");
- whileMethod(strArr);
- System.out.println("for方法");
- foreachMethod(strArr);
- }
- private static void whileMethod(String[] arr) {
- int counter = 0;
- while (counter < arr.length) {
- System.out.print(arr[counter++] + " ");
- }
- System.out.println();
- }
- private static void foreachMethod(String[] arr) {
- for (String s : arr) {
- System.out.print(s + " ");
- }
- System.out.println();
- }
- }
复制代码 |