코드업 기초 100제 (자바): 1001-1027
모든 문제는 코드업에서 참고했습니다.
기초-출력
1001 : 출력하기01
public class Main{
public static void main(String[] args){
System.out.println("문장");
}
}
1002 : 출력하기02
public class Main{
public static void main(String[] args){
System.out.println("Hello World");
}
}
1003 : 출력하기03
public class Main{
public static void main(String[] args){
System.out.println("Hello\nWorld");
}
}
1004 : 출력하기04
public class Main{
public static void main(String[] args){
System.out.println("'Hello'");
}
}
or
public class Main{
public static void main(String[] args){
System.out.println("\'Hello\'");
}
}
1005 : 출력하기05
public class Main{
public static void main(String[] args){
System.out.println("\"Hello\"");
}
}
1006 : 출력하기06
public class Main{
public static void main(String[] args){
System.out.println("\"!@#$%^&*()\"");
}
}
1007 : 출력하기07
public class Main{
public static void main(String[] args){
System.out.println("\"C:\\Download\\hello.cpp\"");
}
}
1008 : 출력하기08
public class Main{
public static void main(String[] args){
System.out.println("\u250C\u252C\u2510");
System.out.println("\u251C\u253C\u2524");
System.out.println("\u2514\u2534\u2518");
}
}
기초-입출력
1010 : 정수 1개 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
System.out.println(input);
scanner.close();
}
}
1011 : 문자 1개 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char input = scanner.next().charAt(0);
System.out.println(input);
scanner.close();
}
}
1012 : 실수 1개 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float input = scanner.nextFloat();
System.out.println(input);
scanner.close();
}
}
1013 : 정수 2개 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int inputFirst = scanner.nextInt();
int inputSecond = scanner.nextInt();
scanner.close();
System.out.printf("%d %d", inputFirst, inputSecond);
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] inputArray = input.split(" ");
int inputFirst = Integer.parseInt(inputArray[0]);
int inputSecond = Integer.parseInt(inputArray[1]);
scanner.close();
System.out.printf("%d %d", inputFirst, inputSecond);
}
}
1014 : 문자 2개 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char inputFirst = scanner.next().charAt(0);
char inputSecond = scanner.next().charAt(0);
scanner.close();
System.out.printf("%c %c", inputSecond, inputFirst);
}
}
1015 : 실수 입력받아 둘째 자리까지 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float input = scanner.nextFloat();
scanner.close();
System.out.printf("%.2f", input);
}
}
1017 : 정수 1개 입력받아 3번 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
scanner.close();
System.out.printf("%d %d %d", input, input, input);
}
}
1018 : 시간 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputTime = scanner.nextLine();
scanner.close();
System.out.println(inputTime);
}
}
1019 : 연월일 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] inputArray = input.split("\\."); //[.]
scanner.close();
System.out.printf("%04d.%02d.%02d",
Integer.parseInt(inputArray[0]), Integer.parseInt(inputArray[1]), Integer.parseInt(inputArray[2]));
}
}
1020 : 주민번호 입력받아 형태 바꿔 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
scanner.close();
System.out.println(input.replace("-", ""));
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
scanner.close();
StringBuilder sb = new StringBuilder(input);
sb.deleteCharAt(input.indexOf('-'));
System.out.println(sb.toString());
}
}
1021 : 단어 1개 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
System.out.println(input);
scanner.close();
}
}
1022 : 문장 1개 입력받아 그대로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
System.out.println(input);
scanner.close();
}
}
1023 : 실수 1개 입력받아 부분별로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] inputArray = input.split("\\.");
System.out.println(inputArray[0] +"\n" + inputArray[1]);
scanner.close();
}
}
or following the guideline in Baeldung:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
int indexOfDecimal = input.indexOf(".");
System.out.println(input.substring(0, indexOfDecimal) +"\n"
+ input.substring(indexOfDecimal+1));
scanner.close();
}
}
1024 : 단어 1개 입력받아 나누어 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
for (int i = 0; i < input.length(); i++) {
System.out.println("\'" + input.charAt(i) + "\'");
}
scanner.close();
}
}
1025 : 정수 1개 입력받아 나누어 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
int numDigit = input.length();
int multiplier = (int)Math.pow(10, numDigit-1);
for (int i = 0; i < numDigit; i++) {
int digit = input.charAt(i) - '0';
System.out.println("[" + digit * multiplier + "]");
multiplier /= 10;
}
scanner.close();
}
}
1026 : 시분초 입력받아 분만 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
String[] inputArray = input.split(":");
System.out.println(inputArray[1]);
scanner.close();
}
}
1027 : 년월일 입력 받아 형식 바꿔 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
String[] inputArray = input.split("\\.");
System.out.println(inputArray[2] + "-" + inputArray[1] + "-" + inputArray[0]);
scanner.close();
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
String[] inputArray = input.split("\\.");
String temp = inputArray[2];
inputArray[2] = inputArray[0];
inputArray[0] = temp;
System.out.println( String.join("-", inputArray));
scanner.close();
}
}
Leave a comment