[백준][java][11021][A+B - 7] import java.util.Scanner; public class Main { // 11021A+B - 7 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); String[] out = new String[t]; for (int i=0; i 🕸 Algorithm/🕸 백준 BaekJoon 2023.10.08
[백준][java][15552][빠른 A+B] import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Main { // 15552빠른 A+B public static void main(String[] args) throws IOException { BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(System.. 🕸 Algorithm/🕸 백준 BaekJoon 2023.10.08
[JAVA]생성자 Constructor 인스턴스가 생성될 때마다 호출되는인스턴스 초기화 메서드 규칙이름이 class 이름과 같아야 한다리턴값이 없다. 그래도 void 안 붙임모든 class는 반드시 생성자를 가진다(안 적으면 complier가 알아서 만들어줌) 기본 생성자Default Constructor 매개변수parameter가 없는 생성자이다.생성자가 하나도 없을 때 complier가 자동으로 추가한다. 생성자 오버로딩 기본생성자가 필수인 이유는 new로 호출할 때마다초기화한 class를 참조변수에 새로운 주소값에 담기위함이겠죠.호출 시, 원하는 대로 사용하려면 매개변수parameter를 담아 호출하려면 생성자 오버로딩이 필요합니다. 매개변수가 있는 생성자 작성시기본생성자 필수기재 생성자의 접근제어자생성자의 접근제어자는 대부분은.. ☕ JAVA/☕ Class & Method 2023.10.03
[백준][java][25314][코딩은 체육과목 입니다] import java.util.Scanner; // 25314코딩은 체육과목 입니다 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); sc.close(); for (int i = 0; i < num/4; i++) { System.out.print("long "); } System.out.print("int"); } } 🕸 Algorithm/🕸 백준 BaekJoon 2023.10.03
[JAVA]오버로딩 Overloading 한 클래스 안에 같은 이름의 method를 여러 개 정의매개변수parameter는 달라도 같은 의미의 기능을 수행한다. 오버로딩이 성립하기 위한 조건method 이름이 같아야 한다.매개변수의 개수 또는 타입이 달라야 한다.반환 타입은 영향없다.❗ 주의long add(int a, long b) {return a+b;}long add(long a, int b) {return a+b;}→ 위 method를 호출시 long(3, 3)과 같이 사용하면 Compiler가 어떤 걸 호출할 지 판단하지 못해 error 발생 참조영상 ☕ JAVA/☕ Class & Method 2023.10.03
[백준][java][25304][영수증] import java.util.Scanner; // 25304영수증 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int sum = sc.nextInt(); int num = sc.nextInt(); int itemPrice = 0; for (int i=0; i < num; i++) { int price = sc.nextInt(); int item = sc.nextInt(); itemPrice += price*item; } sc.close(); System.out.print(sum == itemPrice ? "Yes" : "No"); } } 🕸 Algorithm/🕸 백준 BaekJoon 2023.10.03
[백준][java][8393][합] import java.util.Scanner; // 8393합 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int sum = 0; int num = sc.nextInt(); sc.close(); for (int i = 1; i 🕸 Algorithm/🕸 백준 BaekJoon 2023.10.03
[백준][java][10950][A+B - 3] import java.util.Scanner; // 10950A+B - 3 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int[] times = new int[num]; int[] sum = new int[num]; for (int i=0; i < times.length; i++) { sum[i] += sc.nextInt(); sum[i] += sc.nextInt(); } sc.close(); for (int s : sum) System.out.println(s); } } 입력조건의 테스트케이스 갯수를 먼저 입력한다는 점 주의 int.. 🕸 Algorithm/🕸 백준 BaekJoon 2023.10.01
[백준][java][2739][구구단] import java.util.Scanner; // 2739구구단 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); sc.close(); for (int i = 1; i 🕸 Algorithm/🕸 백준 BaekJoon 2023.10.01
[백준][java][2480][주사위 세개] import java.util.Scanner; // 2480주사위 세개 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int reward = 0; int max = 0; int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); sc.close(); if (a == b) { if (b == c) reward = 1; else reward = 2; max = a; } else if (a == c) { if (c == b) reward = 1; else reward = 2; max = a; } else if (b == c).. 🕸 Algorithm/🕸 백준 BaekJoon 2023.09.30