본문 바로가기

프로그래밍언어/Java

(11)
[자바 기초] 자바 클래스 package com.myspring.week01; public class Course { private String title; private String tutor; private int days; // 기본생성자 public Course() { } // 생성자 public Course(String title, String tutor, int days) { this.title = title; this.tutor = tutor; this.days = days; } // Setter, Getter public void setTitle(String title) { this.title = title; } public void setTutor(String tutor) { this.tutor = tutor; }..
자바로 배우는 자료구조 강의 : https://www.youtube.com/watch?v=18HU7_kyubY&list=PL52K_8WQO5oWz_LYm3xg23m5q9qJXoE4n 자료 : http://alg.pknu.ac.kr/t/2016-2017-java/342 0. 프로젝트 세팅 JDK : 자바 컴파일러를 다운로드한다. Eclipse : IDE를 설치한다. workspace를 설정한다. 자바 프로젝트 세팅 : Eclipse를 실행한다. -> File -> new-> project -> java -> project -> 프로젝트 이름과 경로를 설정하고 생성한다. -> 생성된 프로젝트의 src에 class를 생성하고 psvm을 포함해 생성한다. 1. 변수, 배열, 반복문 - 클래스 이름과 파일 이름은 일치해야 한다. 관습적..
프로그래머스 LV.0 2023-02-13 7의 갯수 class Solution { public int solution(int[] array) { int answer = 0; final char ch = '7'; for(int a : array){ String s = Integer.toString(a); for(int i = 0; i < s.length(); i++){ if(s.charAt(i) == ch){ answer++; } } } return answer; } } 설명 배열에 담긴 각 요소에 7의 갯수를 구한다. [7, 77, 17]의 경우 7의 갯수는 4개이다. 본 풀이는 int형과 String형 변환을 활용해 풀이를 했다. Integer.toString(int i)는 i를 문자열로 변환하며 각 문자열에 문자를 순회하..