プロが教えるわが家の防犯対策術!

java独学しています。
下記の占いで名前を入力すると今日の日付と占いが出てくるものを学習しています。
以下★がないものにするとcsvに1行書き込めましたがfor文を入れると書き込めません。白紙でした。
当方初心者ですのでわかりやすくお答えいただける方是非お願いいたします。

public class Uranai {
public static void main(String[] args) throws IOException{

BufferedReader br = null;
BufferedWriter bw = null;

Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH)+1;
int date = cal.get(Calendar.DATE);
int health=0;
int money=0;
int love=0;
int integrate=0;
String s="";

try {

br = new BufferedReader (new InputStreamReader(System.in));
bw = new BufferedWriter(new FileWriter("uranai.csv"));

★for(;;){

System.out.println(year+"."+month+"."+date+"の運勢を占いましょう");
System.out.println("名前を入力してください");
String name="";
name = (br.readLine());

health=(int)(Math.random()*100+1);
money=(int)(Math.random()*100+1);
love=(int)(Math.random()*100+1);
integrate=((health+money+love)/3);

String result;
if(integrate>=90){
result=("大吉");
}else if(integrate>=60){
result=("中吉");
}else if(integrate>=20){
result=("小吉");
}else{
result=("凶");
}

String uranaiResult =year+","+month+","+date+","+name+","+health+","+money+","+love+","+integrate+","+result;
bw.write(uranaiResult+System.lineSeparator());

System.out.println(name+"さんの本日の占いは");
System.out.println("健康運:"+health+"金運:"+money+"恋愛運:"+love+"総合運:"+integrate+" "+result);

} ★
}catch(FileNotFoundException e){
}catch(IOException ee){
}finally {
try{
if(bw!=null) {
bw.close();
}
if(br!=null) {
br.close();
}
}catch(IOException ee) {}
}
}
}

A 回答 (2件)

ループからどうやって脱出してるんだろう.

    • good
    • 0
この回答へのお礼

納得です!break 入れたらうまくいきました!
素早い回答をありがとうございます。

お礼日時:2021/11/26 12:51

for(;;)の中を略さないで示してもらえますか。


()の中が問題です。
    • good
    • 0
この回答へのお礼

ありがとうございました!

お礼日時:2021/11/26 12:51

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!