<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>z_uiw.log</title>
        <link>https://velog.io/</link>
        <description>개발을 합니다.</description>
        <lastBuildDate>Wed, 11 May 2022 14:48:53 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <copyright>Copyright (C) 2019. z_uiw.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/z_uiw" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[Java_02_Variable(변수)/ VariablePractice]]></title>
            <link>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98-VariablePractice</link>
            <guid>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98-VariablePractice</guid>
            <pubDate>Wed, 11 May 2022 14:48:53 GMT</pubDate>
            <description><![CDATA[<h3 id="변수-연습문제">변수 연습문제</h3>
<h4 id="variablepractice">VariablePractice</h4>
<pre><code class="language-java">package com.br.practice.example;

import java.util.Scanner;

public class VariablePractice {
    public void method1() {
        System.out.print(&quot;이름을 입력하세요 : &quot;);
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        System.out.print(&quot;나이를 입력하세요 : &quot;);
        int age = sc.nextInt();

        sc.nextLine();

        System.out.print(&quot;성별을 입력하세요(남/여) : &quot;);
        char gender = sc.nextLine().charAt(0);

        System.out.print(&quot;키를 입력하세요(cm) : &quot;);
        double height = sc.nextDouble();

        System.out.println(&quot;키 &quot; + height + &quot;인 &quot; + age + &quot;살 &quot; + gender + &quot;자 &quot; + name + &quot;님 반갑습니다^^&quot;);
    }

    public void method2() {
        Scanner sc = new Scanner(System.in);

        System.out.print(&quot;첫 번째 정수를 입력하세요 : &quot;);
        int num1 = sc.nextInt();

        System.out.print(&quot;두 번째 정수를 입력하세요 : &quot;);
        int num2 = sc.nextInt();

        System.out.println(&quot;더하기 결과 : &quot; + (num1 + num2));
        System.out.println(&quot;빼기 결과 : &quot; + (num1 - num2));
        System.out.println(&quot;곱하기 결과 : &quot; + num1 * num2);
        System.out.println(&quot;나누기 몫 결과 : &quot; + num1 / num2);

    }

    public void method3() {
        Scanner sc = new Scanner(System.in);

        System.out.print(&quot;가로 : &quot;);
        double width = sc.nextDouble();

        System.out.print(&quot;세로 : &quot;);
        double height = sc.nextDouble();

        System.out.println(&quot;면적 : &quot; + (width * height));
        System.out.println(&quot;둘레 : &quot; + 2*(width + height));
    }

    public void method4() {
        Scanner sc = new Scanner(System.in);
        System.out.print(&quot;문자열을 입력하세요 : &quot;);

        String str = sc.nextLine();

        // 방법1. 각 문자값을 뽑아서 char 변수에 담아둔 후 출력
        /*
        char ch1 = str.charAt(0);
        char ch2 = str.charAt(1);
        char ch3 = str.charAt(2);

        System.out.println(&quot;첫 번째 문자 : &quot; + ch1);
        System.out.println(&quot;두 번째 문자 : &quot; + ch2);
        System.out.println(&quot;세 번째 문자 : &quot; + ch3);
        */

        // 방법2. 아싸리 char변수에 안담고 바로 뽑아서 출력
        System.out.println(&quot;첫 번째 문자 : &quot; + str.charAt(0));
        System.out.println(&quot;두 번째 문자 : &quot; + str.charAt(1));
        System.out.println(&quot;세 번째 문자 : &quot; + str.charAt(2));

    }
}
</code></pre>
</br>

<hr>
<h4 id="run-실행클래스">Run 실행클래스</h4>
<pre><code class="language-java">package com.br.practice.run;

import com.br.practice.example.VariablePractice;

public class Run {

    public static void main(String[] args) {
        VariablePractice vp = new VariablePractice();
        //vp.method1();
        //vp.method2();
        //vp.method3();
        vp.method4();
    }
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Java_02_Variable(변수)/D_Cast(형변환)]]></title>
            <link>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98DCast%ED%98%95%EB%B3%80%ED%99%98</link>
            <guid>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98DCast%ED%98%95%EB%B3%80%ED%99%98</guid>
            <pubDate>Wed, 11 May 2022 14:48:42 GMT</pubDate>
            <description><![CDATA[<h3 id="형변환--값의-자료형을-바꾸는-것">형변환 : 값의 자료형을 바꾸는 것</h3>
<blockquote>
<h4 id="컴퓨터-내부에서의-값-처리-규칙">컴퓨터 내부에서의 값 처리 규칙</h4>
</blockquote>
<ul>
<li><ol>
<li>대입 연산자를 기준으로 왼쪽과 오른쪽은 같은 자료형이여야된다.
=&gt; 즉, 같은 자료형에 해당하는 값만 대입이 가능함
( 다른 자료형의 값을 대입하고자 한다면 형변환이 필수)
자료형 변수명 = (자료형)값;</li>
</ol>
</li>
<li><ol start="2">
<li>같은 자료형끼리만 연산이 가능 =&gt; 연산 결과 또한 같은 자료형으로 나옴
값 + (자료형)값</br><h4 id="형변환의-종류">형변환의 종류</h4>
</li>
</ol>
</li>
<li><ol>
<li>자동형변환 : 자동으로 형변환이 진행되기 때문에 개발자가 직접 형변환을 시킬 필요없음</li>
</ol>
</li>
<li><ol start="2">
<li>강제형변환 : 자동형변환이 안되서 우리가 직접 형변환을 해줘야됨</br>
<span style="color:red">[주의사항]</span>
boolean은 형변환이 불가함     </li>
</ol>
</li>
</ul>
<blockquote>
<h4 id="자동형변환">자동형변환</h4>
<p>자료형이 다른 두 값 간의 연산(대입, 계산)시 자동으로 값의 범위가 작은 자료형을 큰 자료형으로 변환하여 처리해준다.</p>
</blockquote>
<blockquote>
<h4 id="강제형변환">강제형변환</h4>
<p>큰 범위의 자료형을 작은 범위의 자료형으로 변환시키는 것
실수값을 정수형으로 강제형변환시 소수점 아래 부분은 버려짐 (* 데이터 손실이 발생할 수 있음)</p>
</blockquote>
<h4 id="d_cast">D_Cast</h4>
<pre><code class="language-java">package com.br.variable;

public class D_Cast {

    public void autoCasting() {

        // 1. int(4byte) =&gt; double(8byte)
        int i1 = 12;
        double d1 = /*(double)*/i1; // 12 =&gt; 12.0
        System.out.println(&quot;d1 : &quot; + d1);

        int i2 = 12;
        double d2 = 3.3;

        double result = /*(double)*/i2 + d2; // 12 + 3.3 =&gt; 12.0 + 3.3 =&gt; 15.3
        System.out.println(&quot;result : &quot; + result);

        // 2. int(4byte) =&gt; long(8byte)
        int i3 = 1000;
        long l3 = i3;

        long l4 = 10000/*L*/; 

        // 3. float(4byte) =&gt; double(8byte)
        float f5 = 1.0f;
        double d5 = /*(double)*/f5;

        // ===== 특이 케이스 =====
        // 4. long(8byte) =&gt; float(4byte)
        long l6 = 100000L;
        float f6 = l6;
        // float이 실수형이기 때문에 long형보다 표현 가능한 수의 범위가 더 크다.

        // 5. char(2byte) &lt;=&gt; int(4byte)
        int num = /*(int)*/&#39;A&#39;;
        System.out.println(&quot;num : &quot;+ num);

        char ch = /*(char)*/60;
        System.out.println(&quot;ch : &quot;+ ch);

        // char에는 음수값 저장 불가능 =&gt; 값의 범위가 0 ~ 65535

        // 6. byte 또는 short간의 연산
        byte b1 = 1;
        byte b2 = 10;

        //byte b3 = b1 + b2; // 에러발생 =&gt; byte나 short는 연산시 무조건 int형으로 취급
                             //             연산 결과가 범위가 더 큰 int형임 =&gt; byte형에 대입 불가

        byte b3 = (byte)(b1 + b2); // &quot;강제형변환&quot; 하면 저장 가능


    }

    public void forceCasting() {
        // 강제형변환 : 큰 범위의 자료형을 작은 범위의 자료형으로 변환시키는 것

        // double(8byte) =&gt; float(4byte)
        double d1 = 4.0;
        float f1 = (float)d1;

        // double(8byte) = &gt; int(4byte)
        int iNum = 10;
        double dNum = 5.89;

        //int iSum = iNum + dNum; // 10 + 5.89 =&gt; 10.0 =&gt; 5.89 =&gt; 15.89 (double)
                                         // 연산결과인 double형이 int형 변수에 대입 불가

        // 해결방법 1. 연산결과를 int형으로 강제형변환 후 담기
        int iSum1 = (int)(iNum + dNum); // (int)15.89 =&gt; 15
        System.out.println(&quot;iSum1 : &quot; + iSum1);

        // 해결방법 2. double형 값 하나만 int형으로 강제형변환
        int iSum2 = iNum + (int)dNum; //10 + 5 =&gt; 15
        System.out.println(&quot;iSum2 : &quot; + iSum2);

        // 실수값을 정수형으로 강제형변환시 소수점 아래 부분은 버려짐 (* 데이터 손실이 발생할 수 있음)

        // 해결방법 3. 연산결과를 아싸리 double형 변수에 대입
        double dSum = iNum + dNum;
        System.out.println(&quot;dSum : &quot; + dSum);



    }





}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Java_02_Variable(변수)/C_Printf]]></title>
            <link>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98CPrintf</link>
            <guid>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98CPrintf</guid>
            <pubDate>Wed, 11 May 2022 14:48:31 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>System.out.<strong>print</strong>(출력하고자하는값); // 단지 출력만 함(<strong>줄바꿈 X</strong>)
System.out.<strong>println</strong>(출력하고자하는값); // 출력 후 <strong>줄바꿈</strong> 발생
System.out.<strong>printf</strong>(&quot;출력하고자하는형식==<strong>포맷</strong>&quot;, 값, 값, 값 ...);<br>출력하고자하는 값들이 제시한 형식에 맞춰서 출력 (줄바꿈x)</p>
</blockquote>
<h4 id="포맷형식안에서-쓸-수-있는-키워드">포맷(형식)안에서 쓸 수 있는 키워드</h4>
<ul>
<li>%d : 정수</li>
<li>%f : 실수</li>
<li>%c : 문자</li>
<li>%s : 문자열(문자도 가능)</li>
</ul>
<pre><code class="language-java">package com.br.variable;

public class C_Printf {

    public void printfTest() {

        // System.out.print(출력하고자하는값); // 단지 출력만 함(줄바꿈 X)
        // System.out.println(출력하고자하는값); // 출력 후 줄바꿈 발생

        // System.out.printf(&quot;출력하고자하는형식==포맷&quot;, 값, 값, 값 ...);        
        // 출력하고자하는 값들이 제시한 형식에 맞춰서 출력 (줄바꿈x)

        /*
         * 포맷(형식)안에서 쓸 수 있는 키워드
         * %d : 정수
         * %f : 실수
         * %c : 문자
         * %s : 문자열(문자도 가능)
         */

        int iNum1 = 10;
        int iNum2 = 20;

        // 10 20
        System.out.println(iNum1 + &quot; &quot; + iNum2);
        System.out.printf(&quot;%d %d \n&quot;,iNum1, iNum2);
        //System.out.printf(&quot;%d %d&quot;,iNum1); // 에러발생 =&gt; 두번째 포맷에 들어갈 값이 없어서
        System.out.printf(&quot;%d \n&quot;,iNum1, iNum2); // 상관없다.

        System.out.printf(&quot;%5d \n&quot;, iNum1); // 5칸의 공간 확보 후 오른쪽 정렬 (음수면 왼쪽)
        System.out.printf(&quot;%5d \n&quot;, 250);
        System.out.printf(&quot;%5d \n&quot;, 3000);
        System.out.printf(&quot;%5d \n&quot;, 16);

        double dNum1 = 1.23456789;
        double dNum2 = 4.53;

        System.out.printf(&quot;%f %f \n&quot;,dNum1,dNum2); // 무조건 소수점 아래 6째짜리까지 보여줌
        System.out.printf(&quot;%.2f %.1f \n&quot;,dNum1,dNum2);

        char ch =&#39;a&#39;;
        String str = &quot;Hello&quot;;

        System.out.printf(&quot;문자 : %c, 문자열 : %s \n&quot;, ch, str);
        System.out.printf(&quot;문자 : %C, 문자열 : %S \n&quot;, ch, str);

    }
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Java_02_Variable(변수)/B_KeyboardInput]]></title>
            <link>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98BKeyboardInput</link>
            <guid>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98BKeyboardInput</guid>
            <pubDate>Wed, 11 May 2022 14:48:13 GMT</pubDate>
            <description><![CDATA[<blockquote>
<h3 id="사용자에게-키보드로-값을-입력받는-방법">사용자에게 키보드로 값을 입력받는 방법</h3>
<p>자바에서 <strong>java.util.Scanner클래스</strong>를 만들어놓음
Scanner클래스 안에 <strong>이미 만들어져있는 메소드</strong>들을 <strong>호출</strong>하면 사용가능</br>
<span style="color:red">Scanner sc = new Scanner(System.in);</span> // System.in =&gt; 입력받은 값을 바이트단위로 받아들이겠다.</p>
</blockquote>
<ul>
<li><strong>next()</strong> : 사용자가 입력한 값 중 공백이 있을 경우 <strong>공백 이전</strong>까지의 값만 가져옴</li>
<li><strong>nextLine()</strong> : 사용자가 입력한 모든 값을 읽어옴 (<strong>공백까지</strong>도),
버퍼에서 &quot;엔터&quot; 이전까지의 모든 값을 가져온 후 <strong>&quot;엔터&quot;를 비워주는 역할</strong></li>
<li><strong>그 외의 메소드</strong> : 버퍼에서 &quot;엔터&quot; 이전까지의 값을 가져온 후 <strong>&quot;엔터&quot;를 비워주지 않음</strong></br>
해결방법 : sc.nextLine()이 수행되기 전에 버퍼에 남아있는 &quot;엔터&quot;를 깔끔히 비우기</br></br></li>
<li><strong>문자열</strong>을 입력받을 때 : <strong>sc.nextLine()</strong></li>
<li><strong>정수값</strong>을 입력받을 때 : <strong>sc.nextInt()</strong></li>
<li><strong>실수값</strong>을 입력받을 때 : <strong>sc.nextDouble()</strong></br></br></li>
<li>char gender = sc.nextChar(); // <strong>nextChar()와 같은 메소드 없음!!</strong>
sc.nextLine()으로 문자열로 먼저 읽어들이고
=&gt; charAt(0)을 이용해서 0번 인덱스 자리의 문자 뽑기</li>
</ul>
<blockquote>
<h4 id="1-모니터로-어떠한-값을-출력하기-위해서--systemoutprintprintln">1. 모니터로 어떠한 값을 &quot;출력&quot;하기 위해서 : System.out.print/println()</h4>
</blockquote>
<h4 id="2-키보드로-어떠한-값을-입력하기-위해서--scanner-sc--new-scannersystemin">2. 키보드로 어떠한 값을 &quot;입력&quot;하기 위해서 : Scanner sc = new Scanner(System.in);</h4>
<p>sc.nextLine() : 문자열 읽어들이기
sc.nextInt() : 정수값 읽어들이기
sc.nextDouble() : 실수값 읽어들이기
sc.nextLine().charAt(0) : 문자값 읽어들이기</br>
<span style="color:red">[주의사항]</span>
nextInt() / nextDouble() 뒤에 nextLine()이 와야될 경우
=&gt; nextLine()을 한번 더 써줘서 버퍼에 남은 &quot;엔터&quot;를 비워주는 과정 필요!</p>
<pre><code class="language-java">package com.br.variable;

import java.util.Scanner;

public class B_KeyboardInput { //클래스명 수정하면 파일명까지 수정해야함

    // 사용자에게 키보드로 값을 입력받는 방법

    public void inputScanner1() {

        /*
         *  자바에서 java.util.Scanner클래스를 만들어놓음
         *  Scanner클래스 안에 이미 만들어져있는 메소드들을 호출하면 사용가능
         */

        Scanner sc = new Scanner(System.in); //System.in =&gt; 입력받은 값을 바이트단위로 받아들이겠다.

        // 간단하게 사용자의 정보를 입력받아 출력하는 프로그램 만들기
        System.out.print(&quot;당신의 이름은 무엇입니까 : &quot;);
        // 사용자가 입력한 값을 문자열로 가져오는 메소드 (next(). nextLine())
        // next() : 사용자가 입력한 값 중 공백이 있을 경우 공백 이전까지의 값만 가져옴
        //String name = sc.next();
        String name = sc.nextLine();
        // nextLine() : 사용자가 입력한 모든 값을 읽어옴 (공백까지도)

        System.out.print(&quot;당신의 나이는 몇살입니까 : &quot;);
        int age = sc.nextInt(); // nextInt() : 정수값 읽어들일때 사용

        System.out.print(&quot;당신의 키는 몇 cm입니까(소수점 아래 첫째자리까지 입력) : &quot;);
        double height = sc.nextDouble();

        System.out.println(name + &quot;님은 &quot; + age + &quot;살이며, 키는 &quot; + height + &quot; cm입니다.&quot;);

    }

    public void inputScanner2() {

        Scanner sc = new Scanner(System.in);

        System.out.print(&quot;이름 : &quot;);
        String name = sc.nextLine();

        System.out.print(&quot;나이 : &quot;);
        int age = sc.nextInt();

        /*
         * nextLine() : 버퍼에서 &quot;엔터&quot; 이전까지의 모든 값을 가져온 후 &quot;엔터&quot;를 비워주는 역할
         * 그 외의 메소드 : 버퍼에서 &quot;엔터&quot; 이전까지의 값을 가져온 후 &quot;엔터&quot;를 비워주지 않음
         * 
         * sc.nextInt()/sc.nextDouble() 후 sc.nextLine()이 오게 되면
         * 버퍼에 남아있는 &quot;엔터&quot;를 sc.nextLine()이 인식해서 사용자가 값을 입력했다고 생각
         * 곧바로 읽어들여버림
         * 
         * ==&gt; 해결방법 : sc.nextLine()이 수행되기 전에 버퍼에 남아있는 &quot;엔터&quot;를 깔끔히 비우기
         * 
         */

        // 버퍼에 남아있는 &quot;엔터&quot;비우기
        sc.nextLine();

        System.out.print(&quot;주소 : &quot;);
        String address = sc.nextLine();

        System.out.print(&quot;키(cm) : &quot;);
        double height = sc.nextDouble();        

        System.out.println(name + &quot;님은 &quot;+ age + &quot;살이며, 사는 곳은 &quot; 
                            + address + &quot;이고, 키는 &quot; + height + &quot;cm입니다.&quot;);

        System.out.printf(&quot;%s님은 %d살이며, 사는 곳은 %s이고, 키는 %.1fcm입니다.&quot;, name, age, address, height);
    }

    public void inputScanner3() {

        Scanner sc = new Scanner(System.in);

        // 문자열을 입력받을 때 : sc.nextLine()
        // 정수값을 입력받을 때 : sc.nextInt()
        // 실수값을 입력받을 때 : sc.nextDouble()

        // 이름, 나이, 키, 주소
        System.out.print(&quot;이름은? : &quot;);
        String name = sc.nextLine();

        System.out.print(&quot;나이는? : &quot;);
        int age = sc.nextInt();

        System.out.print(&quot;키는?(cm) : &quot;);
        double height =sc.nextDouble();

        sc.nextLine();

        System.out.print(&quot;주소는? : &quot;);
        String address = sc.nextLine();

        //성별(M/F)
        System.out.print(&quot;성별(M/F) : &quot;);
        //char gender = sc.nextChar(); //nextChar()와 같은 메소드 없음!!
        char gender = sc.nextLine().charAt(0);
        // sc.nextLine()으로 문자열로 먼저 읽어들이고
        // =&gt; charAt(0)을 이용해서 0번 인덱스 자리의 문자 뽑기


        System.out.println( name + &quot;님의 개인정보&quot;);
        System.out.println(&quot;나이 : &quot; + age);
        System.out.println(&quot;키 : &quot; + height);
        System.out.println(&quot;주소 : &quot; + address);
        System.out.println(&quot;성별 : &quot; + gender);

    }

    public void charAtTest() {

        String fruit = &quot;apple&quot;;

        System.out.println(fruit.charAt(0));

        char ch = fruit.charAt(4);
        System.out.println(ch);
    }

    /*
     * 1. 모니터로 어떠한 값을 &quot;출력&quot;하기 위해서 : System.out.print/println()
     * 2. 키보드로 어떠한 값을 &quot;입력&quot;하기 위해서 : 
     *         Scanner sc = new Scanner(System.in);
     *         sc.nextLine() : 문자열 읽어들이기
     *         sc.nextInt() : 정수값 읽어들이기
     *         sc.nextDouble() : 실수값 읽어들이기
     *         sc.nextLine().charAt(0) : 문자값 읽어들이기
     * 
     *     * 주의사항 *
     * nextInt() / nextDouble() 뒤에 nextLine()이 와야될 경우
     * =&gt; nextLine()을 한번 더 써줘서 버퍼에 남은 &quot;엔터&quot;를 비워주는 과정 필요!
     * 
     */
}
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Java_02_Variable(변수)/A_Variable]]></title>
            <link>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98AVariable</link>
            <guid>https://velog.io/@z_uiw/Java02Variable%EB%B3%80%EC%88%98AVariable</guid>
            <pubDate>Wed, 11 May 2022 14:47:58 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>📂 <strong>패키지</strong> : 클래스들을 보관하는 폴더같은 개념 =&gt; 비슷한 역할을 하는 클래스들을 보관</br>
패키지는 <strong>세 단계 이상</strong>으로 만들어주는 걸 권장 (ex) com.회사명.프로젝트명 또는 팀명
1, 2레벨 : 도메인의 역순 (중복방지, 어디서 제작됐는지)
3레벨 : 프로젝트명 또는 팀명 따서 지음</p>
</blockquote>
<pre><code class="language-java">// 기본패키지에 만들면 패키지선언부가 없음
// 패키지 : 클래스들을 보관하는 폴더같은 개념 =&gt; 비슷한 역할을 하는 클래스들을 보관
public class A_Variable {

    // 기본패키지 안에 클래스 만들기 (권장 x)
    //  &gt; 모든 클래스를 기본패키지에 몰아넣으면 관리하기 힘듦 (카테코리별로 분류해서 관리해야 유지보수에 용이)
    //  &gt; 기본패키지에 만들어진 클래스들은 다른 패키지에서 사용불가

    // 패키지는 세 단계 이상으로 만들어주는 걸 권장 (ex) com.회사명.프로젝트명 또는 팀명
    //  &gt; 1, 2레벨 : 도메인의 역순 (중복방지, 어디서 제작됐는지)
    //  &gt; 3레벨 : 프로젝트명 또는 팀명 따서 지음
}
</code></pre>
</br>

<hr>
<h4 id="a_variable">A_Variable</h4>
<blockquote>
<p><strong>1. 변수란 뭔지</strong>
    어떠한 값을 메모리상에 기록하기 위한 공간이다. (박스같은 개념)<br>
<strong>2. 변수를 왜 사용하는지</strong>
    값에 의미를 부여할 목적 (가독성이 좋아짐)
    한 번 값을 저장해두고 계속 사용할 목적으로
    유지보수를 쉽게 하기 위한 목적<br>
<strong>3. 변수를 어떻게 쓰면 되는지</strong>
변수의 선언 (저장할 값을 기록하기 위한 변수를 메모리상에 확보하는 과정) == 변수(박스) 만들겠다!
_[표현법] 자료형 변수명; _</p>
</blockquote>
<ul>
<li>자료형 : 어떤 값을 담아낼지, 어떤 크기의 값을 담아낼지에 대해 변수의 크기 및 모양을 정하는 부분</li>
<li>변수명 : 변수의 이름 (의미부여) =&gt; 여기서 지정한 이름으로 앞으로 호출<br>
_<span style="color:red">[주의할 점] 변수명의 시작은 소문자로!_</span>
여러 단어로 엮어 있는 경우 낙타표기법 지키기 (userName, userAge)<br>
해당 영역({})에 선언한 변수는 해당 영역 안에서만 꺼내 쓸 수 있음 == 지역변수 개념
해당 영역({})에 동일한 변수명으로 선언 불가<br>
변수의 &quot;대입&quot;
<em>[표현법] 변수명 = 값;</em></br>
변수 선언과 동시에 대입
<em>[표현법] 자료형 변수명 = 값;</em><br></li>
<li><em>4. 변수명은 어떻게 지으면 되는지 (명명규칙)*</em></li>
<li>변수명이 같으면 에러발생 (단, 대소문자는 구분)</li>
<li>예약어(이미 자바에서 사용되고 있는 키워드들) 사용 불가</li>
<li>숫자 가능 (단, 숫자로 시작하는건 안됨)</li>
<li>특수문자 가능 (단, _ $ 이외의 특수문자 불가)</li>
<li>권장1) 낙타표기법</li>
<li>권장2) 한글쓰지말것</br></li>
<li><em>5. 상수란 뭔지*</em>
변수와 동일하게 값을 보관할 목적
변수와의 차이점은 값을 변경하는게 불가
즉, 한번 대입된 값은 더이상 변경이 불가</br>
<em>[표현법] final 자료형 상수명;</em></br></br></li>
<li>값 (리터럴) : 프로그램상에 필요한 명시적인 값 / 또는 사용자가 마우스 또는 키보드로 입력한 값</li>
<li>변수 : 값을 저장하기 위한 공간 (메모리상에 만들어짐)</li>
</ul>
<pre><code class="language-java">package com.br.variable;

// 다른 패키지라면 같은 클래스명으로 만드는 것 허용
public class A_Variable {

    public void whatVariable() {
        System.out.println(&quot;변수 사용 전&quot;);
        System.out.println(9160 * 8);
        System.out.println(9160 * 8 * 5);
        System.out.println(9160 * 8 * 5 * 4);
        System.out.println(9160 * 8 * 5 * 4 * 0.1);

        // 1. 변수란 뭔지?
        //      어떠한 값을 메모리상에 기록하기 위한 공간이다. (박스같은 개념)

        int pay = 9160; //시급
        int hour = 8; //하루 중 근무시간
        int day = 5; //일주일 중 근무일수
        int week = 4; //한달 중 근무주수
        double tax = 0.1; //세금 10%
        System.out.println(&quot;변수 사용 후&quot;);
        System.out.println(pay * hour); //하루치 급여
        System.out.println(pay * hour * day); //일주일치 급여
        System.out.println(pay * hour * day * week); //한달치 급여
        System.out.println(pay * hour * day * week * tax); //내야될 세금

        System.out.println(&quot;내 시급 : &quot; + pay + &quot;원&quot;);
        /*
         * 2. 변수를 사용하는 이유
         * -  값에 의미를 부여할 목적 (가독성이 좋아짐)
         * -  한 번 값을 저장해두고 계속 사용할 목적으로
         * -  유지보수를 쉽게 하기 위한 목적
         */
    }

    public void declareVariable() {

        /*
         * 3. 변수의 선언 (저장할 값을 기록하기 위한 변수를 메모리상에 확보하는 과정) == 변수(박스) 만들겠다!
         *    [표현법] 자료형 변수명;
         *    
         *    자료형 : 어떤 값을 담아낼지, 어떤 크기의 값을 담아낼지에 대해 변수의 크기 및 모양을 정하는 부분
         *    변수명 : 변수의 이름 (의미부여) =&gt; 여기서 지정한 이름으로 앞으로 호출
         *    
         *    * 주의할 점 *
         *    - 변수명의 시작은 소문자로
         *    - 여러 단어로 엮어 있는 경우 낙타표기법 지키기 (userName, userAge)
         *    - 해당 영역({})에 선언한 변수는 해당 영역 안에서만 꺼내 쓸 수 있음 == 지역변수 개념
         *    - 해당 영역({})에 동일한 변수명으로 선언 불가
         *    
         *    &gt; 변수의 &quot;대입&quot;
         *        [표현법] 변수명 = 값;
         *    
         *    &gt; 변수 선언과 동시에 대입
         *        [표현법] 자료형 변수명 = 값;
         */

        // * 자료형

        // 1. 논리형 (논리값 : true/false) 1byte
        //boolean bool; // 선언
        //bool = true;  // 대입
        boolean bool = false; // 선언과 동시에 대입
        System.out.println(&quot;bool의 값 : &quot; + bool);

        bool = false;
        bool = 1 + 3 &gt; 2; // 4가 2보다 큽니까? =? 참 == true

        System.out.println(&quot;bool의 값 : &quot; + bool);

        // 2. 숫자형
        // 2_1. 정수형
        byte bNum = 127; // 1byte ( -128 ~ 127 )
        short sNum = 30000; // 2byte 
        int iNum = 100000; // 4byte (-21억xx ~ 21억xx) =&gt; 정수형 중에 가장 대표적인 자료형 (기본형)
        long lNum = 100000000L; // 8byte

        System.out.println(&quot;bNum의 값 : &quot; + bNum);
        System.out.println(&quot;sNum의 값 : &quot; + sNum);
        System.out.println(&quot;iNum의 값 : &quot; + iNum);
        System.out.println(&quot;lNum의 값 : &quot; + lNum);

        //2_2. 실수형
        float fNum = 4.0f; // 4byte (반드시 f를 붙여야함)
        double dNum = 8.0; // 8byte =&gt; 실수형 중에 가장 대표적인 자료형 (기본형) // 크기보다는 더 정확한 값

        System.out.println(&quot;fNum의 값 : &quot; + fNum);
        System.out.println(&quot;dNum의 값 : &quot; + dNum);

        // 3. 문자형
        char ch = &#39;A&#39;; // 2byte
        ch = &#39;강&#39;;

        System.out.println(&quot;ch의 값 : &quot; + ch);

        // 기본자료형(8개) : boolean, char, byte, short, int, long, float, double ========

        // 4. 문자열 (참조자료형)
        String str = &quot;ABC&quot;;

        System.out.println(&quot;str의 값 : &quot; + str);

        //--------------------------------------------------------------------------------

        // 4. 변수 명명 규칙

        // 1) 변수명이 같으면 에러발생 (단, 대소문자는 구분)
        int number;
        //int number;
        int numbEr;

        // 2) 예약어(이미 자바에서 사용되고 있는 키워드들) 사용 불가
        //int public;
        //int class;
        //int true;
        //int abstract;

        // 3) 숫자 가능 (단, 숫자로 시작하는건 안됨)
        int ag2e1;
        //int 1age;

        // 4) 특수문자 가능 (단, _ $ 이외의 특수문자 불가)
        int num_ber;
        int num$ber;
        int _number; // 특수문자로 시작 가능
        //int num!ber;
        //int num@ber;

        // 권장1) 낙타표기법
        String username; // 관례상 틀림
        String userName; // 관례상 맞는 표현

        // 권장2) 한글쓰지말것
        String 이름;

    }

    public void constant( ) {
        /*
         *  5. 상수란 뭔지?
         *     변수와 동일하게 값을 보관할 목적
         *     변수와의 차이점은 값을 변경하는게 불가
         *     즉, 한번 대입된 값은 더이상 변경이 불가
         *     
         *     [표현법] final 자료형 상수명;
         */

        int age = 20;
        age = 21;        
        System.out.println(&quot;age : &quot; + age);

        final int AGE = 20; // 상수명은 주로 다 대문자로 작성
        //AGE = 21;

        System.out.println(&quot;AGE : &quot; + AGE);

        // 대표적인 상수의 예
        System.out.println(&quot;파이 : &quot; + Math.PI);

    }

    /*
     *  - 값 (리터럴) : 프로그램상에 필요한 명시적인 값 / 또는 사용자가 마우스 또는 키보드로 입력한 값
     *  - 변수 : 값을 저장하기 위한 공간 (메모리상에 만들어짐)
     */

}





</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Java_01_myFirstProject/HelloWorld]]></title>
            <link>https://velog.io/@z_uiw/Java01myFirstProjectHelloWorld</link>
            <guid>https://velog.io/@z_uiw/Java01myFirstProjectHelloWorld</guid>
            <pubDate>Wed, 11 May 2022 14:47:36 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>System.out.<strong>println</strong>(출력하고자하는값); =&gt; 해당 출력문 출력후 &quot;한줄 띄어주는&quot; 역할
System.out.<strong>print</strong>(출력하고자하는값); =&gt; 해당 출력문 출력만 하고 끝 (한줄띄어쓰기x)
<strong>백슬래쉬(\) + n</strong> =&gt; 줄바꿈</p>
</blockquote>
<h4 id="helloworld">HelloWorld</h4>
<pre><code class="language-java">package com.br.first; // =&gt; 패키지선언부

// 한줄짜리주석

/*
 * 여러줄
 * 주석
 * 
 * 1. 프로젝트만들기
 * 2. 패키지만들기 (패키지 == 소스코드들을 보관하는 폴더)
 * 3. 클래스만들기
 * 
 */
public class HelloWorld {
    // 메소드 == 기능
    // 첫번째 메소드

    // 두번째 메소드

    // 세번째 메소드 ...

    // 메인 메소드 (실행용 메소드)
    public static void main(String[] args) {

        // 화면에 출력하고 싶을때 출력문을 통해 작업(print, println, printf)

        // System.out.println(출력하고자하는값); =&gt; 해당 출력문 출력후 &quot;한줄 띄어주는&quot; 역할
        System.out.println(&quot;Hello \nWorld!&quot;);

        // System.out.print(출력하고자하는값); =&gt; 해당 출력문 출력만 하고 끝 (한줄띄어쓰기x)
        System.out.print(&quot;안녕하세요\n&quot;); // =&gt; 백슬래쉬(\) + n =&gt; 줄바꿈

        System.out.println(&quot;여러분~!&quot;);
    }

}
</code></pre>
<hr>
<h4 id="a_methodprinter">A_MethodPrinter</h4>
<ul>
<li>같은 클래스 내 메소드 호출시 바로 호출</li>
</ul>
<pre><code class="language-java">package com.br.first;

public class A_MethodPrinter {

        //일반메소드
        //public void 메소드명() {소스코드}
        public void methodA() {
            System.out.println(&quot;메소드A 출력&quot;);
            methodB(); //같은 클래스 내 메소드 호출시 바로 호출

        }

        public void methodB() {
            System.out.println(&quot;메소드B 출력&quot;);
            methodC();
        }

        public void methodC() {
            System.out.println(&quot;메소드C 출력&quot;);
        }
}
</code></pre>
<h4 id="runa">RunA</h4>
<blockquote>
<p>특정 메소드 호출시
해당 메소드 안의 내용이 실행됨!        
<strong>다른 클래스에 있는 메소드를 실행하고자 한다면?</strong></br>        </p>
</blockquote>
<p>1) 실행할 메소드가 있는 클래스를 <strong>생성(new)</strong>이라는 걸 해야됨
[표현법] 클래스명 사용할 이름 = new 클래스명();
        A_MethodPrinter a = new A_MethodPrinter();    </br>    </p>
<blockquote>
<p>해결법1. 해당 클래스가 어떤 패키지에 속해있는지 풀클래스명을 기입하는 방법
com.br.first.A_MethodPrinter a = new com.br.first.A_MethodPrinter();
<strong>해결법2. 단순한 클래스명만을 가지고 생성구문을 쓰되 이 클래스가 어떤 패키지의 클래스인지 선언문(import)추가</strong>
A_MethodPrinter a = new A_MethodPrinter();<br>2) 생성 후 이제 <strong>메소드 호출</strong>
[표현법] 사용할이름.실행시키고자하는메소드명();
a.methodA();</p>
</blockquote>
<pre><code class="language-java">package com.br.run;

import com.br.first.A_MethodPrinter;

public class RunA {

    public static void main(String[] args) {

        // 특정 메소드 호출시
        // 해당 메소드 안의 내용이 실행됨!

        // 다른 클래스에 있는 메소드를 실행하고자 한다면?

        // 1) 실행할 메소드가 있는 클래스를 생성(new)이라는 걸 해야됨
        //[표현법] 클래스명 사용할 이름 = new 클래스명();

        //A_MethodPrinter a = new A_MethodPrinter();

        // 해결법1. 해당 클래스가 어떤 패키지에 속해있는지 풀클래스명을 기입하는 방법
        //com.br.first.A_MethodPrinter a = new com.br.first.A_MethodPrinter();

        // 해결법2. 단순한 클래스명만을 가지고 생성구문을 쓰되 이 클래스가 어떤 패키지의 클래스인지 선언문(import)추가
        A_MethodPrinter a = new A_MethodPrinter();

        // 2) 생성 후 이제 메소드 호출
        //      [표현법] 사용할이름.실행시키고자하는메소드명();
        /*
        a.methodA();        
        a.methodB();        
        a.methodC();
        */

        a.methodA();
    }
}
</code></pre>
</br>


<hr>
<h4 id="b_valueprinter">B_ValuePrinter</h4>
<blockquote>
<p><strong>변수명 원칙</strong></p>
</blockquote>
<ol>
<li><strong>클</strong>래스명 : <strong>대</strong>문자로 시작</li>
<li>패키지명 : 소문자로 시작</li>
<li>메소드명 : 소문자로 시작</li>
<li>변수명 : 소문자로 시작</li>
</ol>
<blockquote>
<p>단, 여러개의 단어를 조합할 경우 <span style="color:red">낙타표기법(Camel Case)</span></br>
ex)
클래스명 Methodprinter =&gt; <strong>MethodPrinter</strong>
메소드명 printtest =&gt; <strong>printTest</strong></p>
</blockquote>
<h4 id="항상-의미있게-이름짓자">항상 의미있게 이름짓자!!</h4>
<pre><code class="language-java">package com.br.first;

public class B_ValuePrinter { //com.br.first.B_ValuePrinter
    /*
     *  ** 원칙 **
     *  1. 클래스명 : 대문자로 시작
     *  2. 패키지명 : 소문자로 시작
     *  3. 메소드명 : 소문자로 시작
     *  4. 변수명 : 소문자로 시작
     *  
     *  단, 여러개의 단어를 조합할 경우 낙타표기법(Camel Case)
     *  ex) 클래스명 Methodprinter =&gt; MethodPrinter
     *      메소드명 printtest =&gt; printTest
     *  
     *  항상 의미있게 이름짓자!!
     */

    // 다양한 종류의 값을 출력하는 기능을 수행하는 메소드
    public void printValue() {
        // 1. 숫자 출력 =&gt; 따옴표없이
        System.out.println(123); //정수
        System.out.println(1.23); //실수

        // 2. 문자(한글자) 출력 =&gt; 홑따옴표 이용
        System.out.println(&#39;a&#39;);

        // 3. 문자열 출력 =&gt; 쌍따옴표 이용
        System.out.println(&quot;안녕하세요&quot;);

        // 4. 연산한 결과값도 출력
        System.out.println(123 + 456);

        // 5. 문자와 숫자는 연산가능 =&gt; 컴퓨터에서는 문자를 숫자로 인식
        System.out.println(&#39;a&#39; + 1); // a == 97

        // 6. 문자열(&quot;&quot;)과 그 외의 값들의 덧셈연산 =&gt; 문자열화 됨(연이어짐)
        System.out.println(&quot;하이&quot; + &#39;a&#39;); // &quot;하이a&quot;
        System.out.println(&quot;안녕하세요&quot; + 111); // &quot;안녕하세요111&quot;        
    }

    public void sumStringNumber() {
        System.out.println(9 + 9); //18
        System.out.println(9 + &quot;9&quot;); //99
        System.out.println(&quot;9&quot; + 9); //99
        System.out.println(&quot;9&quot; + &quot;9&quot;); //99

        System.out.println(&quot;===&quot;);

        System.out.println(9 + 9 + &quot;9&quot;); // 18 + &quot;9&quot; =&gt; &quot;189&quot;
        System.out.println(9 + &quot;9&quot; + 9); // &quot;99&quot; + 9 =&gt; &quot;999&quot;
        System.out.println(&quot;9&quot; + 9 + 9); // &quot;99&quot; + 9 =&gt; &quot;999&quot;
        System.out.println(&quot;9&quot; + (9 + 9)); // &quot;9&quot; + 18 =&gt; &quot;918&quot;
    }
}
</code></pre>
<pre><code class="language-java">package com.br.run;

import com.br.first.B_ValuePrinter;

public class RunB {
    public static void main(String[] args) {
        // 다른 클래스에 있는 메소드 호출
        // 1) 해당 클래스 생성(new)
        // 클래스명 변수 = new 클래스명();
        B_ValuePrinter b = new B_ValuePrinter();

        // 2) 해당 클래스에 실행하고자 하는 메소드 호출
        //    사용할이름.실행할메소드명();
        //b.printValue();
        b.sumStringNumber();
    }
}
</code></pre>
<hr>
]]></description>
        </item>
    </channel>
</rss>