본문 바로가기

JAVA

[Java] 수업 정리 25 (24.11.27)

예제 ) class Example{
                    public static void main(String[] args){
                                  //boolean 변수 yn을 정의하고
                                  //1로 초기화 하세요(true)
 
                                  //만약 yn이 true라면 "안녕"을 출력
                                 //false라면 "안녕하세요"를 출력하세요

                                 //만약 yn이 true라면 "안녕하세요"를 5번 출력
                                //false라면 1부터 5까지 더하세요(for, while 중 편한 것)

 

class Example{
              public static void main(String[] args){              
                              boolean yn = 1

                              if (yn == true){
                                          for(int i = 0;. i < 5; i++)
                             System.out.println ("안녕하세요");
                             } else{ 
                                          int sum = 0;
                                          for(int j = 0; j<6; j++)
                                          sum += j;
                             }
               }
}