본문 바로가기

문제 풀이/명품 JAVA 에센셜3

명품 JAVA 에센셜 3장 실습 문제 풀이 1. 영문 소문자를 하나 입력받고 그 문자보다 알파벳 순위가 낮은 모든 문자를 출력하는 프로그램을 작성하라. public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("영문 소문자 하나를 입력하세요>>"); String aplha = sc.next(); sc.close(); StringBuilder sb = new StringBuilder(); for(int i = 'a'; i < aplha.toCharArray()[0]; i++){ sb.append((char)i); if(i != (aplha.toCharArray()[0]-1)){ sb.append(", "); } } System.out.. 2023. 11. 28.
명품 JAVA 에센셜 2장 실습 문제 풀이 1. 두 정수를 입력받아 합을 구하여 출력하는 프로그램을 작성하라. public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); System.out.println(a + " + " + b + " = " + (a+b)); sc.close(); } Scanner 클래스를 이용할 수 있는지에 대해 알아보기 위한 문제였습니다. 먼저 Scanner 클래스의 객체 sc를 생성해 줍니다.그 뒤에 nextInt()를 이용하여 정수를 입력받은 뒤 형식에 맞게 출력해 주면 됩니다. 2. 2차원 평면에서 하나의 직사각형은 두 점으로 표현된다. (50,50)과 (10.. 2023. 11. 28.
명품 JAVA 에센셜 1장 실습 문제 풀이 1. Welcome!!을 출력하는 자바 프로그램을 작성하라. public static void main(String[] args) { System.out.print("Welcome!!"); } 2. Sorry~~를 출력하는 자바 프로그램을 작성하라. public static void main(String[] args) { System.out.print("Sorry~~"); } 3. "1 2 3 4 5 6 7 8 9"를 출력하는 자바 프로그램을 작성하라. public static void main(String[] args) { System.out.print("1 2 3 4 5 6 7 8 9"); } Open Challenge문제. 실행결과는 다음과 같다. 지시대로 자바 응용프로그램을 작성하라. public.. 2023. 10. 31.