「Java入門」for文でint、double、string型配列の要素を取得する方法
書式
for (データ型 変数名:配列名)
使用例
package com.arkgame.study;
public class CalendarDemo {
//int型配列
protected static int cftA[] = { 21, 31, 41, 51 };
//string型配列
protected static String cftB[] = { "AA01", "BB02", "CC03", "DD04" };
//double型配列
protected static Double cftC[] = { 12.34, 21.35, 35.21, 68.12 };
public static void main(String[] args) {
// int型配列の要素を取得
System.out.println("int型配列の要素下記");
for (int n : cftA) {
System.out.println(n);
}
// String型配列の要素を取得
System.out.println("string型配列の要素下記");
for (String m : cftB) {
System.out.println(m);
}
// Double型配列の要素を取得
System.out.println("Double型配列の要素下記");
for (Double d : cftC) {
System.out.println(d);
}
}
package com.arkgame.study;
public class CalendarDemo {
//int型配列
protected static int cftA[] = { 21, 31, 41, 51 };
//string型配列
protected static String cftB[] = { "AA01", "BB02", "CC03", "DD04" };
//double型配列
protected static Double cftC[] = { 12.34, 21.35, 35.21, 68.12 };
public static void main(String[] args) {
// int型配列の要素を取得
System.out.println("int型配列の要素下記");
for (int n : cftA) {
System.out.println(n);
}
// String型配列の要素を取得
System.out.println("string型配列の要素下記");
for (String m : cftB) {
System.out.println(m);
}
// Double型配列の要素を取得
System.out.println("Double型配列の要素下記");
for (Double d : cftC) {
System.out.println(d);
}
}
package com.arkgame.study; public class CalendarDemo { //int型配列 protected static int cftA[] = { 21, 31, 41, 51 }; //string型配列 protected static String cftB[] = { "AA01", "BB02", "CC03", "DD04" }; //double型配列 protected static Double cftC[] = { 12.34, 21.35, 35.21, 68.12 }; public static void main(String[] args) { // int型配列の要素を取得 System.out.println("int型配列の要素下記"); for (int n : cftA) { System.out.println(n); } // String型配列の要素を取得 System.out.println("string型配列の要素下記"); for (String m : cftB) { System.out.println(m); } // Double型配列の要素を取得 System.out.println("Double型配列の要素下記"); for (Double d : cftC) { System.out.println(d); } }
実行結果
int型配列の要素下記
21
31
41
51
string型配列の要素下記
AA01
BB02
CC03
DD04
Double型配列の要素下記
12.34
21.35
35.21
68.12