Created
December 23, 2010 13:42
-
-
Save konishi/752984 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class FizzBuzz { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
System.out.println("カウント上限を入力して下さい。"); | |
String input = br.readLine(); | |
Data in = new Data(); | |
in.setMax(input); | |
System.out.println("上限は" + in.getMax() + "ですね?(yes/no)"); | |
if (br.readLine().toString().equals("yes")) { | |
FizzBuzz fb = new FizzBuzz(); | |
fb.count(in); | |
fb.show(in); | |
} else { | |
System.out.println("Dead."); | |
} | |
} | |
private Data count(Data in) { | |
for (int i=1; i <= Integer.parseInt(in.getMax()); i++ ) { | |
if (i%3 == 0 && i%5 == 0) { | |
in.setList("FizzBuzz"); | |
} else if (i%3 == 0) { | |
in.setList("Fizz"); | |
} else if (i%5 == 0) { | |
in.setList("Buzz"); | |
} else { | |
in.setList(String.valueOf(i)); | |
} | |
} | |
return in; | |
} | |
private void show(Data in) { | |
for (int i=0; i < in.getList().size(); i++) { | |
System.out.println(in.getList().get(i)); | |
} | |
System.out.println(in.getMax() + "出力されました。"); | |
} | |
} | |
class Data { | |
private String max; | |
private ArrayList<String> list; | |
public Data() { | |
max = "0"; | |
list = new ArrayList<String>(); | |
} | |
public void setMax(String str) { | |
max = str; | |
} | |
public String getMax() { | |
return max; | |
} | |
public void setList(String str) { | |
list.add(str); | |
} | |
public ArrayList<String> getList() { | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment