[JAVA] Programmers 약수의 합 ☑
·
Programmers/java
어떤 수를 나누어떨어지게 하는 수를 그 수 = 약수 8을 1, 2, 4, 8,로 나누면 나누어떨어집니다. 1, 2, 4, 8은 8의 약수입니다. 정답 class Solution { public int solution(int n) { int sum = 0; for (int i = 1; i
[JAVA] Programmers 문자열을 정수로 바꾸기 ☑
·
Programmers/java
빙빙 생각하지 말자. 그냥 형변환 한번이면 된다. 정답: class Solution { public int solution(String s) { return Integer.parseInt(s); } } String인 s를 int로 변환 Integer.paseInt(s); package test01; import java.util.ArrayList; public class CodingTest2 { public static void main(String[] args) { solution("-1234"); } public static int solution(String s) { System.out.print(Integer.parseInt(s)); return Integer.parseInt(s); } }
[JAVA] Programmers 자릿수 더하기 ☑
·
Programmers/java
123을 문자로 형변환해서 끊어주고, 다시 형변환해서 합을 구해주면 된다고 생각했다. 아래는 푼 정답 public class Solution { public int solution(int n) { int sum = 0; int intValue = n; String str = Integer.toString(intValue); String[] num = str.split(""); for(int i = 0; i
[JAVA] 22-07-08 인터페이스를 이용한 주행 모드 바꾸기 문제 ☑
·
STUDY/JAVA
문제 1번 package exam05_instanceof; public interface hipasspay_interface extends pay_interface { public void HipassPay(); } package exam05_instanceof; public interface pay_interface { public void Pay(); } package exam05_instanceof; public interface Vehicle { public void run(); } package exam05_instanceof; import java.util.Scanner; public class Bus implements Vehicle , pay_interface { int inputpay =..
[JAVA]22-07-08 컬렉션 프레임워크 ☑
·
STUDY/JAVA
컬렉션 프레임워크(Collection Framework) 컬렉션 : 사전적의미로 요소(객체)를 수집해 저장하는 것 전부 heap에 들어간다. 배열의 문제점 저장할 수있는 객체 수가 배열을 생성할 때 결정 → 불특정 다수의 객체를 저장하기엔 문제 객체를 삭제했을 때 해당 인덱스가 비게됨 → 낱알이 덤성덤성 빠진 옥수수가 될 수 있다. → 객체를 저장하려면 어디가 비어있는지 확인 //길이가 10인 배열 생성 Product[] array = new Product[10]; //객체 추가 array[0] = new Product("Model1"); array[1] = new Product("Model2"); //객체 검색 Product model1 = array[0]; Product model2 = array[1..
[JAVA] 22-07-07 인터페이스를 활용한 간식 먹기 문제 ☑
·
STUDY/JAVA
문제 : 사람 A,B,C등 여러사람이 있습니다. 젤리중에 망고 포도 딸기가 있습니다. 골라서, 먹습니다. package interfacePack; public interface Customer { public String name(); } package interfacePack; public class Who implements Customer{ //인테페이스는 필드값이 상수여야함 //초기화를 해주어야 했기 때문에 사용하지않음 String name = ""; @Override public String name() { //랜덤으로 이름 설정 while(true){ int personselect = (int)(Math.random()*3) + 1; if(personselect == 1){ name = "비실..
[JAVA-이것이자바다.4장] 조건문과 반복문 확인 문제
·
STUDY/JAVA
for문을 이용해서 1부터 100까지의 정수 중에서 3의 배수의 총합을 구하는 코드를 작성하라 public class ex03 { public static void main(String[] args) { int sum = 0; for(int i =0; i
[JAVA] 22-07-06 인터페이스를 활용한 차 만들기 예제 ☑
·
STUDY/JAVA
Car package sec05.exam01_field_polymorphism; public class Car { //필드값 //인스턴스만들어줌 //인스턴스인 Tire를 인터페이스 Trie로 구현된 HankookTire에 연결해줌 public Tire frontLeftTire = new HankookTire(); public Tire frontRightTire = new HankookTire(); //제한자 차이 Tire backLeftTire = new HankookTire(); Tire backRightTire = new HankookTire(); //브레이크추가 Number01_Brake num1 = new Number01_Brake(); Number02_Brake num2 = new Number0..