본문 바로가기

JAVA172

[Java] String.format을 이용한 문자열 형식 설정하기 public static String format(String format, Object... args); public static String format(Locale l, String format, Object... args); String의 static 메서드인 format 메서드는 문자열의 형식을 설정하는 메서드이다. %d ( = Integer Formatting) 10진수 integer의 형식을 설정할 때 이용한다. int i = 23; System.out.println(String.format("%d_", i));// 23_ System.out.println(String.format("%5d_", i));// 23_ System.out.println(String.format("%-5d_, i).. 2024. 1. 9.
[Java의 정석 - 기초편] 2-11. 형식화된 출력 : printf() 2-11. 형식화된 출력 : printf() println()의 단점 : 출력 형식 지정 불가 실수의 자리수 조절 불가 10진수로만 출력됨 printf()로 출력 형식 지정 가능 System.out.printf("%.2f", 10.0/3);// 3.33 System.out.printf("%d", 0x1A);// 26 System.out.printf("X", 0x1A);// 1A printf()의 지시자 지시자 설명 %b 불리언(boolean) 형식으로 출력 %d 10진(decimal) 정수의 형식으로 출력 %o 8진(octal) 정수의 형식으로 출력 %x, %X 16진(hexa-decimal) 정수의 형식으로 출력 %f 부동 소수점(floating-point)의 형식으로 출력 %e, %E 지수(expon.. 2024. 1. 9.
[Bronze V] 백준 - 2393. Rook : Java 2393번: RookThe rook art, exactly as shown below, with no extra blank spaces. In particular, a line must not end with a blank space.www.acmicpc.net    문제 : You have just learned how to output text to the screen and your teacher has challenged you to create an ASCII art of a chess piece. You have decided to make your favorite piece, the rook.출력 : The rook art, exactly as shown below, with no extra.. 2023. 12. 19.
[Bronze V] 백준 - 2377. Pottery : FreeBASIC 2377번: Pottery3D printing is becoming more and more prominent in today’s society. Unfortunately, you don’t currently have access to a 3D printer. Instead, you can just print an item with your knowledge of coding! Print a clay pot.www.acmicpc.net    문제 : 3D printing is becoming more and more prominent in today’s society. Unfortunately, you don’t currently have access to a 3D printer. Instead, you.. 2023. 12. 19.
[Bronze V] 백준 - 2372. Livestock Count : Ada 2372번: Livestock CountPrint the table below as shown. The character “-”, is a dash not an underscore.www.acmicpc.net  문제 : Print a table that describes the current count of all your livestock.출력 : Print the table below as shown. The character “-”, is a dash not an underscore.예제 : Animal Count-----------------Chickens 100Clydesdales 5Cows 40Goats 22Steers .. 2023. 12. 19.
[Bronze V] 백준 - 2338. 긴자리 계산 : Java 2338번: 긴자리 계산첫째 줄에 A+B, 둘째 줄에 A-B, 셋째 줄에 A×B를 출력한다. 각각을 출력할 때, 답이 0인 경우를 제외하고는 0으로 시작하게 해서는 안 된다(1을 01로 출력하면 안 된다는 의미).www.acmicpc.net   문제 : 두 수 A, B를 입력받아, A+B, A-B, A×B를 구하는 프로그램을 작성하시오. 입력 : 첫째 줄에 A가, 둘째 줄에 B가 주어진다. 각각의 수는 10진수로 1,000자리를 넘지 않으며 양수와 음수가 모두 주어질 수 있다.출력 : 첫째 줄에 A+B, 둘째 줄에 A-B, 셋째 줄에 A×B를 출력한다. 각각을 출력할 때, 답이 0인 경우를 제외하고는 0으로 시작하게 해서는 안 된다(1을 01로 출력하면 안 된다는 의미). import java.math.. 2023. 12. 19.