✅ 문제

 

 

✅ 코드

 

class Solution {
    public int solution(int num, int n) {
        int answer = 0;
        
        if((num % n==0)){
            answer= 1;
        } else{
            answer=0;
        }
            
        
        return answer;
    }
}

 

✅ 문제

✅ 코드

 

class Solution {
    public String solution(String str1, String str2) {
       String answer = "";

		for(int i=0;i<str1.length();i++) {
			answer=answer+str1.charAt(i)+str2.charAt(i);
		}
		
		return answer;
    }
}

문제

사전 구상

 

  • my_string을 s까지 추출 후 overwrite_string 을 합친다.
  • "s+overwrite_string.length()" 길이만큼 my_string에서 추출 후 합쳐줌.

 

✅ 결과

 

package lv_0;

class overwrite_String {
	public String solution(String my_string, String overwrite_string, int s) {

		String myStr = my_string;
		String overStr = overwrite_string;

		// 예시) "He11oWor1d" / "lloWorl" / s =2
		// myStr.substring(0, s) -> "He"
		// overStr = "lloWorl"
		// my_string.substring(overStr.length() + s) -> 7+2 = 9번째 문자 추 
		//위 3개를 합쳐주면 변경된 문자열로 출
		//
		return myStr.substring(0, s) + overStr + my_string.substring(overStr.length() + s);

	}

}

 


 

문제


사전 구상

  • 자연수 n 이 주어지면 n을 2로 나눠서 나머지가 0이면 짝수 출력! 아니면 홀수 출력

package lv_0;

import java.util.Scanner;

public class oddeven {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int result = n % 2;
		
		if (result == 0) {
			System.out.printf("%d is even", n);
		} else {
			System.out.printf("%d is odd", n);
		}

	}

}

 

결과


https://github.com/Beast-IT/Programmers.git

 

GitHub - Beast-IT/Programmers: 코딩테스트 연습!

코딩테스트 연습! Contribute to Beast-IT/Programmers development by creating an account on GitHub.

github.com

Github에 들어가시면 원본 코드 보실 수 있습니다.

✅  문제


✅ 사전 구상

  • System.in.read(); 를 사용해서 바이트 데이터를 읽어서 int값으로 저장.

  • 아스키코드값을 보면 A~Z(65~90), a~z(97~122) 대소문자 간의 32 차이가 나는 것을 볼 수 있음.
  • 조건문으로 데이터 값이 '65~90' 범위면 '+32'를 해주고 나머지 범위는 '-32'를 해주면 될꺼같음.

✅ 코드구현

 

package lv_0;

import java.io.IOException;

public class changetheupperandlowercase {

	public static void main(String[] args) throws IOException {

		int[] str = new int[7];

		for (int i = 0; i < 7; i++) {
			str[i] = System.in.read();
		}

		for (int j = 0; j < 7; j++) {
			
			if (str[j] >= 65 && 90 >= str[j]) {
				
				str[j] += 32;
				
			} else {
				
				str[j] -= 32;
				
			}
		}

		for (int k = 0; k < 7; k++) {
			System.out.write(str[k]);

		}

		System.out.flush();
	}

}

망했다... 값은 나오는데 문제를 잘 못 읽어서 문자로 받아왔다....문자열로 받아와서 다시 코드수정을 해야겠음... ❌ 


package lv_0;

import java.io.IOException;
import java.util.Scanner;

public class changetheupperandlowercase {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();

		for (int i = 0; i < str.length(); i++) {

			char one = str.charAt(i);// str에서 한문자씩 받아
			int a = one;// a에 ASCII 코드값 저장

			// A~Z -> 65 ~ 90
			// a~z -> 97 ~ 122
			
			//대소문자 변환 
			if (65 <= a && a <= 90) {
				a+=32;
			}else {
				a-=32;
			}
			System.out.write(a);//write를 이용해 코드값을 대소문자로 인코	
		}
		System.out.flush();


	}

}

🏋️ 위 코드로 수정완료!🏋️

 


https://github.com/Beast-IT/Programmers.git

 

GitHub - Beast-IT/Programmers: 코딩테스트 연습!

코딩테스트 연습! Contribute to Beast-IT/Programmers development by creating an account on GitHub.

github.com

Github에 들어가시면 원본 코드 보실 수 있습니다.

+ Recent posts