JavaStudy/Basic

[Java] 9.배열

LeeDaniel 2024. 11. 5. 10:26

 [ 배열의 생성 ] 

public class DefineDemo {

  public static void main(String[] args) {
		
    String[] cypherGroup = { "로라스", "휴톤", "루이스", "타라" };
      System.out.println( cypherGroup[0]);
      System.out.println( cypherGroup[1]);
      System.out.println( cypherGroup[2]);
      System.out.println( cypherGroup[3]);
    }
}
public class DefineDemo {

  public static void main(String[] args) {
		
    String[] cypherGroup = new String[4];
        
    cypherGroup[0] = "로라스";
    System.out.println( cypherGroup[0]);
        
    cypherGroup[1] = "휴톤";
    System.out.println( cypherGroup[1]);
        
    cypherGroup[2] = "루이스";
    System.out.println( cypherGroup[2]);
        
    cypherGroup[3] = "타라";
    System.out.println( cypherGroup[3]);
        
    System.out.println( cypherGroup.length );
  }
}


 [ for-each ] 

public class DefineDemo {

  public static void main(String[] args) {
		
    String[] cyphers = { "로라스", "휴톤", "루이스", "타라", "트리비아" };
		
      for( String e : cyphers ) {
        System.out.println( e + " 님이 전투에 참여했습니다");
      }  
  }
}

 

반응형

'JavaStudy > Basic' 카테고리의 다른 글

[Java] 11.입력과 출력  (0) 2024.11.05
[Java] 10.메소드(method)  (0) 2024.11.05
[Java] 8.반복문  (0) 2024.11.05
[Java] 7.논리 연산자  (0) 2024.10.22
[Java] 6.조건문  (0) 2024.10.21