programmers 기초 Day1

Hwani·2024년 6월 1일

프로그래머스 DAY 1~25

목록 보기
27/51

프로그래머스의 입문 Day1~25까지 매일 풀어서 공부를 했다.
이제 기초 트레이닝 Day1~25를 매일 풀고 공부할 예정이다.

문제 - 문자열 출력하기

풀이

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        
        System.out.println(a);
    }
}

문제 - a와 b 출력하기

풀이

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println("a = "+ a);
        System.out.println("b = "+ b);
    }
}

문제 - 문자열 반복해서 출력하기

풀이

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = sc.nextInt();
        
        for (int i = 1; i <= n; i++) {
            System.out.print(str);
        }
    }
}

문제 - 대소문자 바꿔서 출력하기

풀이

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();

        String result = "";
        for (int i = 0; i < a.length(); i++) {
            char ch = a.charAt(i);
            if (Character.isUpperCase(ch)) {
                result += Character.toLowerCase(ch);
            } else {
                result += Character.toUpperCase(ch);
            }
        }
        System.out.println(result);
    }
}

문제 - 특수문자 출력하기

풀이

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        System.out.println("!@#$%^&*(\\'\"<>?:;\n");
    }
}
profile
개발자될거야

0개의 댓글