본문 바로가기

Java6

[Java] Generic Generic이란? class hello{ T name; public hello(T name){ this.name = name; } } 를 Generic이라 부른다. 아래 코드를 보자 class Hello{ T text; public Hello(T text){ this.text = text; } void hi(){ System.out.println(text); } } public class Main{ public static void main(String[] args){ Hello hello = new Hello("안녕"); hello.hi(); } } //출력 안녕 이 코드를 나중에 까먹었을 수 도 있는 나를 위해 차근차근 설명해보자면 Class Hello type을 지정할 수 있는 Generic Cl.. 2022. 7. 23.
[Java] Arrays.asList()은 무엇인가 Arrays.asList() 란? 일반 배열을 ArrayList로 바꿔준다. int[] Int_Array = {1,2,3,4,5}; List list = Arrays.asList(Int_Array); Arrays.asList()의 리턴 값 ArrayList (a)를 리턴하는 모습을 알 수 있다. 여기서 ArrayList ()는 우리가 흔히 아는 그 ArrayList Class가 아닌 Arrays class 안에 따로 정의된 private static class이다 (add 함수가 정의되어 있지 않다) //Java Arrays.class 파일 public static List asList(T... a) { return new ArrayList(a); } Arrays.asList() 알아야 할 점 밑의 코드.. 2022. 7. 21.
[Algorithm] 백준 2577번 자바 첫 알고리즘을 풀어 보았다 백준 2577번 package baekjoon.problem; // 세 개의 자연수 A, B, C가 주어질 때 A × B × C를 // 계산한 결과에 0부터 9까지 각각의 숫자가 몇 번씩 쓰였는지를 // 구하는 프로그램을 작성하시오. // 예를 들어 A = 150, B = 266, C = 427 이라면 // A × B × C = 150 × 266 × 427 = 17037300 이 되고, // 계산한 결과 17037300 에는 0이 3번, 1이 1번, 3이 2번, 7이 2번 public class Problem_2577 { public static void main(String[] args) { int[] Int_Count_Array = new int[10]; int A =.. 2022. 7. 20.
(Java) 함수 기초 2022년 6월 11일 새벽 5시 너무 빨리 잤다.... Java 함수에 대한 이야기를 시작해 보도록 하겠다. (Java) 함수 함수의 기본 형태 [접근 제한자][반환 타입] 함수 이름(매개변수){ } [접근 제한자] : Public, Protected, Default, Private (위에 대해서는 나중에 다시 글을 쓸 것임) [반환 타입] : Void, Int, String, Boolean.. 등등 (매개변수) : 파라미터 라고도 한다. //코드 package javatest; public class Main { public static void main(String[] args) { move(); } public static void move() { System.out.println("move");.. 2022. 6. 11.
(JAVA) 배열 Java 배열 선언법 int[] arr = new int[n]//1. int[] arr = null;//2. arr = new int[n]; int[] arr = {2,4,5,3,3,2};//3. int[] arr = new int[] {3,5,7,8};//4. new는 생성자 나중에 class를 배울때 사용 위 사진 처럼 배열이 생성 됨 Stack 메모리에 있는 arr변수가 heap 메모리에 있는 배열을 참조 즉 arr변수는 주소만 가지고 있다고 생각하면 된다. //배열 출력 하는 법 int[] arr = new int[10] for(int i = 0; i < 10; i++){ System.out.println(arr[i]); } 출력 //출력 0 0 0 0 0 0 0 0 0 0 2022. 6. 6.
Java 반복문 For 문 for(int i = 0; i 2022. 6. 5.