Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 공부
- Operating System
- 분할메모리할당
- 스프링
- Spring
- 백준
- 타입스크립트
- CPU 스케줄링
- 리덕스장바구니
- 토이프로젝트
- 알고리즘
- error
- Java
- C++
- js to ts
- 일상
- web
- 자료구조
- OS
- 정렬
- 기초100제
- Redux
- codeup
- react-redux
- 코드업
- 프로그래머스
- 협업
- memory
- 파이썬
- react
Archives
- Today
- Total
감자튀김 공장🍟
[CodeUP]JAVA 1012~1021 본문
반응형
[1012]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float x = scanner.nextFloat();
System.out.printf("%f", x); // 이렇게 출력해본게 처음이였다...
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float x = scanner.nextFloat();
System.out.println(x);
}
}
[1013]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
System.out.printf("%d %d", a, b);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
System.out.println(a + " " + b);
}
}
[1014]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char x = scanner.next().charAt(0);
char y = scanner.next().charAt(0);
System.out.printf("%c %c", y, x);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char x = scanner.next().charAt(0);
char y = scanner.next().charAt(0);
System.out.println(y + " " + x);
}
}
[1015]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float x = scanner.nextFloat();
System.out.printf("%.3f", x);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float x = scanner.nextFloat();
System.out.println(String.format("%.3f", x));
}
}
[1017]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
System.out.printf("%d %d %d", a, a, a);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
System.out.println(a + " " + a + " " + a);
}
}
[1018]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
System.out.println(a);
}
}
[1019]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
String b[] = a.split("[.]");
for(int i = 0; i < b.length; i++) {
if(b[i].length() < 2) {
b[i] = "0" + b[i];
}
}
System.out.println(String.format("%s.%s.%s", b[0], b[1], b[2]));
}
}
위 코드처럼 짰는데 출력 조건에 %02d를 사용하면 2칸을 사용해 출력하는데, 한 자리 수인 경우 앞에 0을 붙여 출력한다. 라는 조건이 있었다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
String b[] = a.split("[.]");
int year = Integer.parseInt(b[0]);
int month = Integer.parseInt(b[1]);
int day = Integer.parseInt(b[2]);
System.out.println(String.format("%04d.%02d.%02d", year, month, day));
}
}
[1020]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
String b[] = a.split("-");
String c = b[0] + b[1];
System.out.println(c);
}
}
더 짧게 짠 코드가 있나 찾아봤더니 아래와 같은 방법도 있더라!
자바 관련 코드를 많이 안짜봐서 낯선 기능이였다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
a = a.replaceAll("-", "");
System.out.println(a);
}
}
[1021]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
System.out.println(a);
}
}
반응형
'Algorithm > CodeUp' 카테고리의 다른 글
[Codeup]JAVA 1052~1061 (0) | 2021.03.15 |
---|---|
[CodeUp]JAVA 1042~1051 (0) | 2021.03.14 |
[CodeUp]JAVA 1032~1041 (0) | 2021.03.13 |
[CodeUp]JAVA 1022~1031 (0) | 2021.03.13 |
[CodeUp]JAVA 1001~1011 (0) | 2021.03.11 |
Comments