📌Back-End/프로그래머스
Java 프로그래머스 코딩 기초 트레이닝 Day 1 출력
구 일
2024. 4. 26. 20:26
728x90
반응형
문자열 출력하기
import java.util.Scanner;
/**
* 코딩 기초 트레이닝 Day 1
* 문자열 출력하기
*/
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
System.out.println(a);
sc.close();
}
}
a와 b 출력하기
import java.util.Scanner;
/**
* 코딩 기초 트레이닝 Day 1
* a와 b 출력하기
*/
public class Main2 {
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 +"\nb = " + b);
sc.close();
}
}
문자열 반복해서 출력하기
import java.util.Scanner;
/**
* 코딩 기초 트레이닝 Day 1
* 문자열 반복해서 출력하기
*/
public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int n = sc.nextInt();
str = str.repeat(n);
System.out.println(str);
sc.close();
}
}
대소문자 바꿔서 출력하기
import java.util.Scanner;
/**
* 코딩 기초 트레이닝 Day 1
* 대소문자 바꿔서 출력하기
*/
public class Main4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
StringBuilder sb = new StringBuilder();
int step = 'a' - 'A';
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) >= 'a' && a.charAt(i) <= 'z') {
sb.append((char) (a.charAt(i) - step));
} else {
sb.append((char) (a.charAt(i) + step));
}
}
System.out.println(sb);
sc.close();
}
}
특수문자 출력하기
/**
* 코딩 기초 트레이닝 Day 1
* 특수문자 출력하기
*/
public class Main5 {
public static void main(String[] args) {
System.out.println("!@#$%^&*(\\'\"<>?:;");
}
}
728x90
반응형