강의

멘토링

커뮤니티

Inflearn Community Q&A

parkkeonwoo's profile image
parkkeonwoo

asked

Introduction to Java Algorithm Problem Solving: Coding Test Preparation

3. Words in a Sentence (indexOf(), substring())

String[] 으로 선언한 s 변수가 제 생각대로 출력이 되지 않음. (문제풀이엔 상관 업지만, 개념적인 부분)

Written on

·

212

0

import java.util.Scanner;

public class Main3 {

public String solution(String str) {
String answer = "";

int m = Integer.MIN_VALUE;
String[] s = str.split(" ");
System.out.println(s); // 이렇게 하면 ["it" , "is" , "time"] 이렇게 보일 줄 알았는데 왜 안 보일까?
for (String x : s) {
System.out.println(x);
}

return answer;

}

public static void main(String[] args) {
Main3 T = new Main3();
Scanner kb = new Scanner(System.in);
String str = kb.nextLine(); // next는 공백을 기준으로 한 단어 또는 한 문자씩 입력받는다. 쉽게 말해 공백 이후의 글자는 날라간다?! nextLine은 문장 전체가 공백 포함해서 통으로 입력됨
System.out.println(T.solution(str));
}

}


질문

위의 코드 중에에서
        System.out.println(s); 

이 부분이 이렇게 하면 ["it" , "is" , "time"] 이렇게 보일 줄 알았는데 왜 안 보일까요
?
java코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

파이썬이나 자바스크립트는 배열으 변수명을 출력하면 배열의 원소들을 다 출력해주지만

C++, 자바는 배열이름이 주소이기때문에 보여주지 않는것 같습니다.

parkkeonwoo's profile image
parkkeonwoo

asked

Ask a question