【java】txtデータを読み込む。【初心者】
mokabuu
mokabuu.com

[adsense]
public class Main {
private final static int MAX_CARD_NUM = 100;
public static void main(String args[]){
Map<Integer, Boolean> cards = init();
for(int i = 2; MAX_CARD_NUM >= i; i++){
int tmp = i;
while(tmp <= MAX_CARD_NUM){
boolean isUp = cards.get(tmp);
if(isUp){
cards.put(tmp, false);
}else{
cards.put(tmp, true);
}
tmp += i;
}
}
printer(cards);
}
private static Map<Integer, Boolean> init(){
Map<Integer, Boolean> cards = new HashMap<Integer, Boolean>();
int index = 1;
while(index <= MAX_CARD_NUM){
cards.put(index, false);
index++;
}
return cards;
}
private static void printer(Map<Integer, Boolean> cards){
int index = 1;
while(index <= MAX_CARD_NUM){
if(!cards.get(index)){
System.out.println(index);
}
index++;
}
}
}
個人的にはstatic void main(String arg[])の
中のforの中にwhileみたいなのをどうにかしてやりたい所存でした。
フィードバックで言われたのは
「順番に並んでる言うて言われてるんだからListで良いじゃん。」とのこと。
確かに・・・。
とりあえず朝日を眺めたら出直して来ます・・・。