[트러블 슈팅] 3. 문자열 배열할 때 []를 넣지 않았을 때

귤's avatar
Mar 18, 2025
[트러블 슈팅] 3. 문자열 배열할 때 []를 넣지 않았을 때
해결법
  • string [ ] 변수명 {” “,” “} 기억하기
  • 출력할 때 번지수로 입력 (클래스 명.변수명[번지수];)
package ex01; // Dog(강아지) - 이름 (name), 색깔(color), 좋아하는 간식들 (foods) - "개껌", "뼈다귀" import org.w3c.dom.ls.LSOutput; class Person { static String name = "홍길동"; static int age = 20; } class Dog { static String name = "포비"; static String color = "하얀색"; static String[] foods = {"개껌", "뼈다귀"}; } // 문자열(이름)과 숫자(나이)를 함께 저장하고 싶을 때 public class Var05 { public static void main(String[] args) { System.out.println(Person.name); System.out.println(Person.age); System.out.println(Dog.name); System.out.println(Dog.color); System.out.println(Dog.foods[0]); System.out.println(Dog.foods[1]); } }
notion image
 
Share article

gyul