java
1 String[] birthday = new String[5]; 2 birthday[0] = "19880511"; 3 birthday[1] = "19800411"; 4 birthday[2] = "19920615"; 5 birthday[3] = "19761105"; 6 birthday[4] = "19900511"; 7 8 // 4.誕生日のリストを作る。要素数は5、一つ自分の誕生日(19900511) 9 List <String> list = new ArrayList<String>(); 10 list.add("田中次郎"); 11 list.add("山中一郎"); 12 list.add("田山次郎"); 13 list.add("竹中次郎"); 14 list.add("田中一郎"); 15 16 for(int i = 0; i < birthday.length; i++) { 17 Date d = new Date(); 18 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 19 int now = Integer.parseInt(sdf.format(d)); 20 int birth = Integer.parseInt(birthday[i]); 21 int ages = (now - birth) / 10000; 22 String aaa = list.get(i); 23 aaa = aaa + ages; 24 System.out.println(aaa); 25 list.add(aaa); 26 27 28 } 29 30 for (int i = 0; i < list.size(); i++) { 31 System.out.println(aaa); 32 } 33 34
###意図
リストに名前と年齢を格納するのになぜfor文を配列の長さにそろえるのか
なぜnew Date()コンストラクタでエラーがでるのか知りたいです
回答1件
あなたの回答
tips
プレビュー