import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a =  sc.nextInt();
        //sc.nextLine();
        System.out.println(a);
        String s = sc.nextLine();
        System.out.println(s);
    }

}

 

nextInt는 엔터를 버퍼에 남기기 때문에

다음에 s를 입력하기 전에 엔터가 남아있어서

공백이 출련된다.

 

이것을 수정하기 위해 

sc.nextLine()을 사용하면

엔터의 버퍼를 지워주기 때문에

다음 문자를 입력할 수 있다.

 

import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a =  sc.nextInt();
        sc.nextLine();
        System.out.println(a);
        String s = sc.nextLine();
        System.out.println(s);
    }

}

 

 

 

숫자만 입력 두번 할 시

nextLine()이 필요없다.

import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a =  sc.nextInt();
        //sc.nextLine();
        System.out.println(a);
        int s = sc.nextInt();
        System.out.println(s);
    }

}

 

 

 

 

StringBuilder는 문자열을 자주 이어붙이거나 수정할 때 사용하는 클래스입니다.
String과 달리 변하지 않는(immutable) 게 아니라 변하는(mutable) 문자열을 다룹니다.

 

 

 

 

 

 

즉 새로운 문자열을 만들 번거로움 없이

즉각적으로 문자열을 수정할 때 용이하다.

 

StringBulider는 기본적으로 문자열이 아닌 배열

 

 

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String before = sc.next();
        System.out.println(before);
        int after = Integer.parseInt(before.substring(0,2));
        System.out.println(after);
    }

}

 

Integer.parseInt()는 문자열(String) 로 되어 있는 숫자를 정수(int) 로 바꿔주는 함수

 

 

'Study > ' 카테고리의 다른 글

[Java] StringBuilder  (0) 2025.11.20
[Java] charAt을 활용하여 숫자를 문자열로 변환  (0) 2025.11.17
[Java] Array.sort()  (0) 2025.11.17
[Java] Integer.MIN_VALUE  (0) 2025.11.16
[Tip] 맥 SVN 설치 - snailSVN  (0) 2024.07.21
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String T  =  sc.next();
        int sum = 0;
        for(int test_case=0;test_case<T.length();test_case++){
            sum  += T.charAt(test_case) - '0';
        }
        System.out.println(sum);
    }
}

 

각 입력받은 숫자들의 자리수 별로 합을 구한다.

예를들어 5624면 5 + 6 + 2 + 4 인 17이된다.

입력을 숫자가 아닌 문자열로 받으면

'0'은 0의 아스키코드인 48

'1'은 1의 아스키코드인 49

...

이렇게 실제 수보다 48 이 크게나오므로

 

공통된 48인 '0'을 빼주며

각 자리를 반복문을 통해 더해준다.

'Study > ' 카테고리의 다른 글

[Java] StringBuilder  (0) 2025.11.20
[Java] Integer.parseInt(String.substring(num1,num2)) + String.format("%02d", num)  (0) 2025.11.18
[Java] Array.sort()  (0) 2025.11.17
[Java] Integer.MIN_VALUE  (0) 2025.11.16
[Tip] 맥 SVN 설치 - snailSVN  (0) 2024.07.21

Arrays.sort()란?

자바에서 배열을 오름차순(작은 → 큰) 으로 정렬해주는 기능이다.

사용 방법:

 
Arrays.sort(arr);

이 한 줄이면 배열 arr 안에 있던 값들이 자동으로 정렬됨.

 

 

 

 

package SWEA;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];

        for(int i = 0; i < N; i++){
            arr[i] = sc.nextInt();
        }

        Arrays.sort(arr);

        int midIndex = N/2;
        System.out.println(arr[midIndex]);

    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(Integer.MIN_VALUE);
    }
}

 

 

 

-2147483648

 

 

public class Main {
    public static void main(String[] args) {
        System.out.println(Integer.MAX_VALUE);
    }
}

 

 

 

2147483647

 

 

 

Integer.MIN_VALUE와 Integer.MAX_VALUE는

자바에서 int 타입이 가질 수 있는 가장 작은 값을 의미

맥을 사용하게 기존에 사용하던 tortoise svn과 호환이 되지 않아

versions등 여러가지를 찾아보다가

snailSVN을 찾게 되어 lite가 아닌 유료버전을 설치하였다.

사용방법에 대해 자세히 설명해놓은 분의 글이 있어서 포스팅한다.

 

 

 

 

 

https://orbit-orbit.tistory.com/entry/Mac-%EB%A7%A5-%EC%9A%A9-SVN-

%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0-SnailSVN-Lite

 

[Mac] 맥 용 SVN 연결하기 : SnailSVN Lite

회사 업무로 인해 Mac에서 SVN을 사용하게 되었으므로 SnailSVN Lite를 활용하게 되었다. Mac의 SnailSVN은 window의 tortoiseSVN과 비슷하다고 하지만, 사용해 본 적이 없어서 모름. 우선 App Store에서 SnailSVN Lit

orbit-orbit.tistory.com

 

'Study > ' 카테고리의 다른 글

[Java] Array.sort()  (0) 2025.11.17
[Java] Integer.MIN_VALUE  (0) 2025.11.16
[Tip] 텍스트 코루틴 애니메이션  (0) 2024.07.16
[Tip]룰렛 원하는 곳에 위치 + 텍스트 출력  (0) 2024.06.29
[Tip] Mathf.DeltaAngle  (0) 2024.06.29

 

 

 

 

 

 

IEnumerator CoTextFlow(string text)
{
    dialogText.text = "";
    string str = null;
    int length = 0;
    bool isScriptEnd = false;
    while (!isScriptEnd)
    {
        foreach (char ch in text)
        {
            str = str + ch;
            yield return new WaitForSeconds(0.035f);
            dialogText.text = str;
        }
        isScriptEnd = true;
    }
}

'Study > ' 카테고리의 다른 글

[Java] Integer.MIN_VALUE  (0) 2025.11.16
[Tip] 맥 SVN 설치 - snailSVN  (0) 2024.07.21
[Tip]룰렛 원하는 곳에 위치 + 텍스트 출력  (0) 2024.06.29
[Tip] Mathf.DeltaAngle  (0) 2024.06.29
[Tip] Object.FindObjectOfType  (0) 2024.06.11

현재 룰렛은 8등분이 되어 있고

각각 360 / 8인 45도로 구성되어 있다.

그러므로 이 가운데 값은 22.5도이다.

룰렛을 개발자가 편하게 컨트롤 할 수 있도록 만들었다.

 

360도 * 횟수를 적용하여 여러번 돌아가고 거기에 지정한 extraAngle을 더해주면된다.

 

회전횟수를 선택할 수 있고 스탭을 조절함으로서 속도를 조절할 수 있다.

 

 

아래는 개발자들은 이미 사전에 클릭을 하면 알 수 있게 항목을 출력하도록 변경

나오는 것은 랜덤으로 변경

즉, 랜덤에 따라 특정 각도가 결정되고 그에 따라 개발자들은 출력결과를 미리 알수 있고,

유저들은 원하는 각도를 보게 되는 것이다.

 

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UI;

public class RouletteTest : MonoBehaviour
{
    [SerializeField] private Button btnGetIem;
    [SerializeField] private Roulette _roulette;
    //[SerializeField] private float targetAngle = -22.5f; //클로버를 겨냥

    private string[] itemNames = { "폭탄" , "기력회복", "폭탄", "체력회복", "폭탄", "금화획득","폭탄", "네잎클로버"};
    private float[] targetAngles =
    {
        22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f
    };
    void Start()
    {
        btnGetIem.onClick.AddListener(() =>
        {
            int idx = UnityEngine.Random.Range(0, 8); // 0 ~ 7
            Debug.Log($"<color=yellow>{itemNames[idx]}</color>");
            _roulette.StartRotate(targetAngles[idx]);
        });
    }

}

 

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UI;

public class RouletteTest : MonoBehaviour
{
    [SerializeField] private Button btnGetIem;
    [SerializeField] private Roulette _roulette;
    //[SerializeField] private float targetAngle = -22.5f; //클로버를 겨냥

    private string[] itemNames = { "폭탄" , "기력회복", "폭탄", "체력회복", "폭탄", "금화획득","폭탄", "네잎클로버"};
    private float[] targetAngles =
    {
        22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f
    };
    void Start()
    {
        btnGetIem.onClick.AddListener(() =>
        {
            int idx = UnityEngine.Random.Range(0, 8); // 0 ~ 7
            Debug.Log($"<color=yellow>{itemNames[idx]}</color>");
            _roulette.StartRotate(targetAngles[idx]);
        });
    }

}

'Study > ' 카테고리의 다른 글

[Tip] 맥 SVN 설치 - snailSVN  (0) 2024.07.21
[Tip] 텍스트 코루틴 애니메이션  (0) 2024.07.16
[Tip] Mathf.DeltaAngle  (0) 2024.06.29
[Tip] Object.FindObjectOfType  (0) 2024.06.11
[Tip] RenderSettings  (0) 2024.06.05

https://docs.unity3d.com/ScriptReference/Mathf.DeltaAngle.html

 

Unity - Scripting API: Mathf.DeltaAngle

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com

'Study > ' 카테고리의 다른 글

[Tip] 텍스트 코루틴 애니메이션  (0) 2024.07.16
[Tip]룰렛 원하는 곳에 위치 + 텍스트 출력  (0) 2024.06.29
[Tip] Object.FindObjectOfType  (0) 2024.06.11
[Tip] RenderSettings  (0) 2024.06.05
[팁] Slider.onValueChanged  (0) 2024.06.05

+ Recent posts