coding

    [ Programmers] 핸드폰 번호 가리기[Java]

    [ Programmers] 핸드폰 번호 가리기[Java]

    문제 설명 프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요. 제한 조건 s는 길이 4 이상, 20이하인 문자열입니다. 입출력 예 풀이 class Solution { public String solution(String phone_number) { String answer = ""; for(int i = 0; i < phone_number.length();i++){ if (i

    [Programmers] 2016년 [Java]

    [Programmers] 2016년 [Java]

    문제 설명 2016년 1월 1일은 금요일입니다. 2016년 a월 b일은 무슨 요일일까요? 두 수 a ,b를 입력받아 2016년 a월 b일이 무슨 요일인지 리턴하는 함수, solution을 완성하세요. 요일의 이름은 일요일부터 토요일까지 각각 SUN,MON,TUE,WED,THU,FRI,SAT 입니다. 예를 들어 a=5, b=24라면 5월 24일은 화요일이므로 문자열 TUE를 반환하세요. 제한 조건 2016년은 윤년입니다. 2016년 a월 b일은 실제로 있는 날입니다. (13월 26일이나 2월 45일같은 날짜는 주어지지 않습니다) 입출력 예 풀이 class Solution { public String solution(int a, int b) { String answer =""; int [] temp = {3..

    [Bakjoon/2920] 음계 [Java]

    [Bakjoon/2920] 음계 [Java]

    문제 다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8부터 1까지 차례대로 연주한다면 descending, 둘 다 아니라면 mixed 이다. 연주한 순서가 주어졌을 때, 이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을 작성하시오. 입력 첫째 줄에 8개 숫자가 주어진다. 이 숫자는 문제 설명에서 설명한 음이며, 1부터 8까지 숫자가 한 번씩 등장한다. 출력 첫째 줄에 ascending, descending, mixed 중 하나를 출력한다. 풀이 import java.ut..

    [Programmers]  하샤드 수 [Java]

    [Programmers] 하샤드 수 [Java]

    문제 설명 양의 정수 x가 하샤드 수이려면 x의 자릿수의 합으로 x가 나누어져야 합니다. 예를 들어 18의 자릿수 합은 1+8=9이고, 18은 9로 나누어 떨어지므로 18은 하샤드 수입니다. 자연수 x를 입력받아 x가 하샤드 수인지 아닌지 검사하는 함수, solution을 완성해주세요. 제한 조건 x는 1 이상, 10000 이하인 정수입니다. 입출력 예 입출력 예 #1 10의 모든 자릿수의 합은 1입니다. 10은 1로 나누어 떨어지므로 10은 하샤드 수입니다. 입출력 예 #2 12의 모든 자릿수의 합은 3입니다. 12는 3으로 나누어 떨어지므로 12는 하샤드 수입니다. 입출력 예 #3 11의 모든 자릿수의 합은 2입니다. 11은 2로 나누어 떨어지지 않으므로 11는 하샤드 수가 아닙니다. 입출력 예 #4..

    [Programmers] 예산(서머코딩/윈터코딩/2018) [Java]

    [Programmers] 예산(서머코딩/윈터코딩/2018) [Java]

    문제 설명 S사에서는 각 부서에 필요한 물품을 지원해 주기 위해 부서별로 물품을 구매하는데 필요한 금액을 조사했습니다. 그러나, 전체 예산이 정해져 있기 때문에 모든 부서의 물품을 구매해 줄 수는 없습니다. 그래서 최대한 많은 부서의 물품을 구매해 줄 수 있도록 하려고 합니다. 물품을 구매해 줄 때는 각 부서가 신청한 금액만큼을 모두 지원해 줘야 합니다. 예를 들어 1,000원을 신청한 부서에는 정확히 1,000원을 지원해야 하며, 1,000원보다 적은 금액을 지원해 줄 수는 없습니다. 부서별로 신청한 금액이 들어있는 배열 d와 예산 budget이 매개변수로 주어질 때, 최대 몇 개의 부서에 물품을 지원할 수 있는지 return 하도록 solution 함수를 완성해주세요. 제한사항 d는 부서별로 신청한 ..

    [Programmers] 문자열 내 p와 y의 개수[Java]

    [Programmers] 문자열 내 p와 y의 개수[Java]

    문제 설명 대문자와 소문자가 섞여있는 문자열 s가 주어집니다. s에 'p'의 개수와 'y'의 개수를 비교해 같으면 True, 다르면 False를 return 하는 solution를 완성하세요. 'p', 'y' 모두 하나도 없는 경우는 항상 True를 리턴합니다. 단, 개수를 비교할 때 대문자와 소문자는 구별하지 않습니다. 예를 들어 s가 pPoooyY면 true를 return하고 Pyy라면 false를 return합니다. 제한사항 문자열 s의 길이 : 50 이하의 자연수 문자열 s는 알파벳으로만 이루어져 있습니다. 입출력 예 입출력 예 #1 'p'의 개수 2개, 'y'의 개수 2개로 같으므로 true를 return 합니다. 입출력 예 #2 'p'의 개수 1개, 'y'의 개수 2개로 다르므로 false를 ..

    015 - Conditional Statement Practice 1

    015 - Conditional Statement Practice 1

    The variable "num" holds an integer user input Write a conditional statement starting on line 9 that does the following: If num is positive, print "__ is positive" If num is negative, print "__ is negative" Examples: In: 5 5 is positive In: -2 -2 is negative In: 0 (no output for zero) import java.util.*; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); ..

    011 - String Methods Practice 2

    011 - String Methods Practice 2

    Given three variables: String str int start int end Print out the following string: The substring of (str) from (start) to (end) is (substring from start to end, inclusive) Sample output: In: lolwut Start: 2 End: 4 The substring of lolwut from 2 to 4 inclusive is lwu PLEASE NOTE that we are counting the end index in our output! lolwut 012345 import java.util.Scanner; class Main { public static v..

    010 - String Methods Practice 1

    010 - String Methods Practice 1

    Given a String (already declared for you as str), do the following: Print out the following: "The first 3 letters of ___ is ___" For example, if the input is "banana", your output should be "The first 3 letters of banana is ban" import java.util.Scanner; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.out.print("in:"); String str = inp.nextLine(..

    009 - String Methods - substring

    009 - String Methods - substring

    For you to do: (all output should be one per line) On line 6, write a print statement that prints out a substring of str starting at index 5 and going to the end On line 7, write a print statement that prints out a substring of str starting at index 7 and ending at index 10 On line 10, fill in the () in substring so that it prints "harambe" On line 11, fill in the () in substring so that it prin..

    008 - String Methods - indexOf

    008 - String Methods - indexOf

    For you to do: (the output should be one per line) Print out the position of the first occurrence of "c" Print out the position of the first occurrence of " " Print out the position of the first occurrence of the variable target1 Print out the position of the first occurrence of the variable target2 class Main { public static void main(String[] args) { String str = "abracadabra alakazam"; String..

    007 - String Methods - charAt

    007 - String Methods - charAt

    For you to do: ALL print statements in this exercise should be on one line, no newlines. Print out the character in the 5th index of the String str Print out the character in the 8th index of the String str Print out the character in the 1st index of the String str Print out the index in the i-th index of the String str (i is a variable already declared for you) class Main { public static void m..

    006 - String Methods - Length

    006 - String Methods - Length

    For you to do: Create a String named "name" and assign the value "Timmy" to it Print out the length of the string variable 'name' class Main { public static void main(String[] args) { String name="Timmy"; System.out.println(name.length()); } }

    005 - Creating Variables and Printing 5

    005 - Creating Variables and Printing 5

    Creating Variables and Printing 5 For you to do: Create a String variable called "name" and set it to "Chen" Create an integer variable called "age" and set it to 50 Create an integer variable called "iq" and set it to the value of age (do NOT use ' = 50') Print the value of name Print the value of age without skipping a new line Print the value of iq class Main { public static void main(String[..

    004 - Creating Variables and Printing 4

    004 - Creating Variables and Printing 4

    Creating Variables and Printing 4 Print out the following pattern: * ** *** ## # class Main { public static void main(String[] args) { System.out.println("*"); System.out.println("**"); System.out.println("***"); System.out.println("##"); System.out.println("#"); } }

    003 - Creating Variables and Printing 3

    003 - Creating Variables and Printing 3

    Creating Variables and Printing 3 For you to do: Create a boolean variable called "isTrue" and set it to false Create a double variable called "money" and set it to 99999.99 Print the variable "money" first Then print the variable "isTrue" without skipping to the next line. class Main { public static void main(String[] args) { boolean isTrue=false; double monet=99999.99; System.out.print(monet);..

    002 - Creating Variables and Printing 2

    002 - Creating Variables and Printing 2

    2019/11/26 Creating Variables and Printing 2 For you to do: Create an integer variable on line 4 and set it to the value 21. class Main { public static void main(String[] args) { int age=21; System.out.println(age); } }

    001 - Creating Variables and Printing 1

    001 - Creating Variables and Printing 1

    2019/11/26 Creating Variables and Printing Them For you to do: Create two String variables called firstName and lastName respectively. Assign the String "Bob" to firstName and "Jones" to lastName. Print firstName and lastName, one per line. Each should use a different print statement. import java.util.*; class Main { public static void main(String[] args) { String firstName ="Bob"; String lastNa..