Java/코드업3 코드업 1025 - [기초-입출력] 정수 1개 입력받아 나누어 출력하기(설명) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.next(); char[] li = a.toCharArray(); for(int i = 0; i i; j--) // 0의 개수 지정 { System.out.print("0"); } System.out.print("]\n"); sc.close(); } } } tocharArray() : 문자열(S.. 2024. 1. 29. 코드업 1082 - [기초-종합] 16진수 구구단? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(16); for(int i = 1; i < 16; i++) { System.out.printf("%X*%X=%X\n",n,i,n*i); } sc.close(); } } sc.nextInt(16)을 하면 16진수 정수로 받아줌 printf에서 %x or %X 지시자를 이용하면 16진수 정수의 형식으로 출력 2024. 1. 29. 코드업 1079 -[기초-종합] 원하는 문자가 입력될 때까지 반복 출력하기 import java.util.Scanner; public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { char ch = sc.next().charAt(0); System.out.println(ch); if (ch == 'q') break; } sc.close(); } } while(true)를 통해 문자를 계속 입력 charAt() : String 타입의 데이터(문자열)에서 특정 문자를 char 타입으로 변환 println으로 문자 한 개 출력 후 줄바꿈 ch = q면 break문에 걸려서 while문 빠져나옴 2024. 1. 29. 이전 1 다음