for(int price : prc),for迴圈讀出陣列內的內容
class Array_Access_ForEach{
public static void main(String[] args){
int prc[] = {200, 350, 200,500,600};
String prcName[] = {"白雪公主","七個小孩","八隻豬","九本書","實在厲害"};
System.out.print("書的價格為:");
for(int price : prc)
System.out.print(price + " ");
for(String price:prcName)
System.out.println(price+"");
}
}
public static void main(String[] args){
int prc[] = {200, 350, 200,500,600};
String prcName[] = {"白雪公主","七個小孩","八隻豬","九本書","實在厲害"};
System.out.print("書的價格為:");
for(int price : prc)
System.out.print(price + " ");
for(String price:prcName)
System.out.println(price+"");
}
}
留言
張貼留言