Created
October 5, 2018 08:09
-
-
Save heuristicwave/608f4cb6f5293f02ade4f702e3b53a9d 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
class SentenceWriter { | |
public static void main(String[] args) { | |
SentenceWriter mySentenceWriter = new SentenceWriter(); | |
mySentenceWriter.writeMySentence(args); | |
} | |
public void writeMySentence(String[] args) { | |
for (int i=0; i < args.length; i++) { | |
System.out.println(args[i]); | |
} | |
} | |
} | |
//////////////////////////////////////////////////////////////////////////////////////////////// | |
/* | |
컴퓨터야 나는 지금 내가 키보드로 치는 문장을 너와 연결된 모니터에 출력해주는 제품(Object)을 만들고 싶어. | |
그 제품의 이름을 SentenceWriter라고 이름을 지을 거고, 이 제품의 설계도(class)를 이제부터 작성해 볼게. */ | |
class SentenceWriter { | |
/* | |
우선 키보드로 내가 작성한 여러 단어들 (Strings[])을 args라는 저장소에 받아서 본격적(main)으로 제품이 | |
돌아가게 할거야. 그런데 이 제품은 누구나 공개적으로(public) 공통적으로(static) 사용할 수 있어야 하지. | |
그리고 내가 하라는 일만하면 되고, 종료될 때 특별히 가져와야 할 것은 없단다(void). */ | |
public static void main(String[] args) { | |
/* | |
자 그러면, 네가 해야 할 가장 첫번째 일은 내가 만든 설계도 대로, 실제 문장을 쓸 수 있는 새로운 | |
SentenceWriter라는 실제 제품(new SentenceWriter())을 하나 만들어야 해. 그 제품에 이름을 주고 싶은데, | |
처음으로 만든거니 mySenteneWriter라고 특별히 붙여줄게. */ | |
SentenceWriter mySentenceWriter = new SentenceWriter(); | |
/* | |
자 이 제품은 이제 내가 키보드로 입력한 단어들을 실제로 출력하는 행동을 해야하는데, 그 행동의 이름이 | |
writeMySentence야. 이 행동은 복잡해서 헷갈리지 않으려고 내가 아래 따로 설명을 써놨어. 아참 네가 무엇을 | |
출력해야 하는지 알아야 하니까 args를 writeMySentence와 함꼐 보내줄게. */ | |
mySentenceWriter.writeMySentence(args); | |
} | |
/* | |
이 친구도 누구나 공개적(public)으로 사용할 수 있단다. 대신 공통으로 사용하지는 못하고, 첫 제품인 | |
mySentenceWriter만 사용할 수 있게 하려고, 공통(static)으로 사용할 수 있는 기능은 생략 할게. 이 행동도 | |
내가 하라는 일만 끝나고 종료될 때, 특별히 가져와야 할 것은 없어(void). */ | |
public void writeMySentence(String[] args) { | |
/* | |
내가 키보드로 입력한 여러 단어들을 args가 가지고 있는데 그 개수(args.length)만큼 순서대로 출력해 줬음 | |
좋겠어. 그런데 너는 0번을 항상 첫번째 라고 인식하니까, 첫번쨰 단어의 번호를 0으로 지정해서 i에 저장할거고 | |
그 다음에 실제 내 시스템(System)의 출력 통로(out)를 통해 첫번째 단어를 한 줄에 출력할 거야.... */ | |
for (int i=0; i < args.length; i++) { | |
System.out.println(args[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Writing Code Letter