본문 바로가기

전체 글115

[프로그래머스] 두 수의 나눗셈 class Solution { public int solution(int num1, int num2) { int answer = 0; double temp = 0; temp = (double)num1/num2; temp = temp*1000; answer = (int)temp; return answer; } } 정수 num1 과 num2가 매개변수로 주어질 때, num1을 num2로 나눈 값에 1,000을 곱한 후 정수 부분을 return 하도록 soltuion 함수를 완성해주세요. int타입의 매개변수를 나누어 값을 double로 만든 후, *1000을해서 int로 타입변경해주고 answer에 값 넣어주자. int 타입은 정수형이라 소수점 아래 나머지를 남기지 않는다. 그래서 temp = (double.. 2022. 10. 4.
[Spring] 매개변수 순서와 데이터 바인딩 파라미터를 2개 넘기던 중 두 변수의 이름이 모호해 이름을 바꾸었다. MypageController /** * 친구 찾기 */ @ResponseBody @GetMapping(value = "/searchFriend.do") public Map searchFriend(String friendId, HttpServletRequest request, HttpServletResponse response) throws IOException { friendId = request.getParameter("userId"); HttpSession session = request.getSession(true); String userId = (String)session.getAttribute(SessionConstant.L.. 2022. 10. 4.
[프로그래머스] (java) 자연수 뒤집어 배열로 만들기 import java.util.*; class Solution { public int[] solution(long n) { String nStr = String.valueOf(n); //문자열 뒤집기 StringBuffer sb = new StringBuffer(nStr); String reverse = sb.reverse().toString(); int[] answer = new int[nStr.length()]; //n의 길이로 초기화 int ar = 0; for(int i=0; i< nStr.length();i++){ //char을 int 변환 ar = reverse.charAt(i)-'0'; answer[i] = ar; } return answer; } } input 값이 long이기 때문에 St.. 2022. 9. 25.
[프로그래머스] mysql Datetime 타입 컬럼 값 String 으로 형식 지정하기 테이블에 등록된 모든 레코드에 대해, 각 동물의 아이디와 이름, 들어온 날짜를 조회하는 SQL문을 작성해주세요. 이때 결과는 아이디 순으로 조회해야 합니다. SELECT animal_id, name, DATE_FORMAT(datetime,'%Y-%m-%d') AS 날짜 FROM animal_ins ORDER BY animal_id DATE_FROMAT(날짜컬럼, '%Y-%m-%d') AS 컬럼이름 설정 2022. 9. 25.