728x90
☕ main()메소드 안의 내용은 차례대로 실행된다
- main()메소드 안의 내용이 한줄씩 실행된다.
- System.out.println("김성박");
1) 아래의 코드는 "김성박"이라는 이름을 출력한다.
2) 그리고 줄바꿈을 하게 된다. 그렇기 때문에 다음 줄에 이메일이 출력된다.
public class MyProfile {
public static void main(String[] args) {
System.out.println("김성박");
System.out.println("urstory@gmail.com");
System.out.println("여자");
}
}
☕ print()메소드는 줄바꿈을 하지 않는다
- println()메소드는 괄호 안의 내용을 출력하고 줄바꿈 하지만, print()메소드는 괄호 안의 내용만 출력한다 .줄바꿈을 하지 않는다.
- System.out.println(); 는 아무것도 출력하지 않고 줄바꿈만 한다.
☕ Rectangle 클래스
- 너비가 별 10개, 높이가 별 10개인 사각형을 출력한다
public class Rectangle {
public static void main(String[] args) {
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
System.out.println("**********");
}
}
☕ 높이가 200인 사각형을 출력하려면?
- 만약 높이가 10,000인 사각형을 출력하라고 문제가 바뀐다면?
- 컴퓨터가 가장 잘 하는 일은 반복하는 일이다.
☕ while 반복문을 이용해 높이가 10인 사각형 출력하기
public class Rectangle2 {
public static void main(String[] args) {
int i = 1;
while(i<=10){
System.out.println("**********");
i = i+ 1;
}
}
}
- 실행하면, Rectangle 클래스와 같다는 것을 알 수 있다.
728x90
'개발&etc > JAVA' 카테고리의 다른 글
[java] 정수형 타입 byte, short, int, long (0) | 2023.03.06 |
---|---|
[java] 논리형 타입과 논리 연산자(비교, 논리) (0) | 2023.03.06 |
[java] 변수와 리터럴 (0) | 2023.03.06 |
[JAVA] CharAt(int i) - '0' 은 무엇인가? (0) | 2023.02.27 |
[자바] 문자열 배열 반환하기: toCharArray() (0) | 2023.02.21 |