Loading...

자바 초보부터 B형까지 - 자바에서 정렬을 하는 기본적인 방법들 -

1. Arrays.sort() import java.util.Arrays; Arrays.sort(arr)은 배열 arr을 오름차순 정렬 import java.util.Arrays; public class Main{ public static void main(String[] args){ int[] arr = new int[]{12,41,37,81,19,25,60,20}; Arrays.sort(arr); for(int i = 0; i < 8; i++){ System.out.print(arr[i] + " "); //12, 19, 20, 25, 37, 41, 60, 81 } } } 2. 부분정렬 특이하게 구간 인덱스를 명시하면 해당 구간만 정렬해줄 수도 있다 Arrays.sort(arr,시작 index, 끝 i..

2023. 2. 26. 23:43

자바 초보에서 B형까지5 -문자열 필수지식-

1. 공백이 없는 문자열 입력받기 문자열의 타입은 String이고 공백이 없는 문자열은 sc.next()로 입력받을 수 있다. import java.util.Scanner; public class Main { public static void main(String[] args) { // 여기에 코드를 작성해주세요. Scanner sc = new Scanner(System.in); String s = sc.next(); System.out.println(s); System.out.println(s); } } 문자열은 각각 원소에 대한 참조로 charAt(index) 형태로 참조 가능하다. 첫번째 문자를 참조할려면 charAt(0)이다. 그래서 문자 하나를 가지고 올때 sc.next().charAt(0); ..