INTRODUCTION TO JAVA

Whitespace 공백

Before we explore what we can do with variables, let’s learn how to keep code organized in Java.

변수로 무언가를 할 수 있는가를 보기 전에, 자바에서 코드가 어떻게 정돈되는지 봅시다.

Whitespace is one or more characters (such as a spacetabenter, or return) that do not produce a visible mark or text. Whitespace is often used to make code visually presentable.

공백은 눈에 보이지 않는 하나 혹은 그 이상 캐릭터(스페이스 바, 탭, 엔터, 백스페이스 등) 문자를 말합니다.

공백은 코드가 눈에 보기 좋게 하기 위해서 자주 사용됩니다.

Java will ignore whitespace in code, but it is important to know how to use whitespace to structure code well. If you use whitespace correctly, code will be easier for you and other programmers to read and understand.

자바 언어는 코드에서 공백을 무시하는데, 공백을 어떻게 쓰는 지를 알고 있는 것은 코드를 잘 짜기 위해서는 중요하빈다. 공백을 잘 쓸 수 있게 되면, 코드는 어떤 프로그래머가 읽어도 보기 쉽고 이해하기 쉽게 작성될 수 있습니다.


public class WhiteSpace {

public static void main(String[] args) {


 char isFormatted = ' ';   // 캐릭터 이름 isFormatted에 space 하나가 저장되어 있음.

    System.out.println(isFormatted);   // 출력 스페이스 한개 그리고 자동 엔터(줄 바꿈)

    System.out.println(" ");                // 문자열 스페이스 한개 그리고 자동 엔터(줄 바꿈) 출력

                string a = " ";  // a라는 string data type 변수에 " " 스페이스 한개 저장

    System.out.println(a);     // a string 변수 출력 , " " 그리고 줄바꿈 출력

}

}

위 코드를 run or execute 하게되면 어떤 결과가 나올까요? 상상해보셨나요?

아마 아무것도 나타나지 않을 것입니다. 아무 것도 화면에 안나왔다면 코드를 올바르게 작성하신 것입니다.

[Java] Variables 변수 공부하기 !


public class Variables {

public static void main(String[] args){

int myNumber = 42;

boolean Hey = true;

char professor = 'F';

}

}



Problems !

1) What's data type of myNumber

2) What's data type of Hey ?

3) What's data type of professor ?

[Java] Boolean Data Type, 불린 데이터 타입


public class DataTypesB {

public static void main(String[] args) {


System.out.println(true);

System.out.println(false);


}

}


[Result]

true

false


이전까지 integer type, 정수형 타입을 알아보았습니다.

이번에는 Boolean type입니다. 한글로는 불린 Boolean 이렇게 불려지곤 하는데, 참, 거짓을 판별해야 할 때 사용되는 데이터 타입입니다.

참과 거짓이 구분 불가능하다면 Boolean data type이 사용될 수 없습니다. 명제라고도 합니다.

[Java] Data Type : Int, 데이터 타입 : 정수형


public class DataTypes{

public static void main(String[] args){

int g=17;

System.out.println(g); //1

System.out.println(17); //2 

System.out.println("17"); //3

}

}


[Result]

17

17

17


모두 17을 가르키는 데이터타입 Data Type 입니다.

g는 integer type으로써 정수숫자 17을 저장하고 있는 변수이고,

2번은 그냥 integer을 출력한 것이고, 3번째 줄은 "17"이라는 문자열을 출력한 것입니다.

모두 같은 값을 가리키지만 구체적인 내용과 data type이 다르다는 것을 구분할 수 있어야 합니다.

+ Recent posts