본문 바로가기

프로그래밍

(133)
자바의 정석 연습문제 7-22 아래는 도형을 정의한 Shape클래스이다. 이 클래스를 조상으로 하는 Circle클래스와 Rectangle클래스를 작성하시오. 이 때, 생성자도 각 클래스에 맞게 적절히 추가해야 한다.(1) 클래스명 : Circle조상클래스 : Shape멤버변수 : double r - 반지름(2) 클래스명 : Rectangle조상클래스 : Shape멤버변수 : double width - 폭, double height - 높이메서드 :1. 메서드명 : isSquare기 능 : 정사각형인지 아닌지를 알려준다.반환타입 : boolean매개변수 : 없음 [ 문제 ] abstract class Shape { Point p; Shape() { this(new Point(0,0)); } Shape(Point p) { this.p =..
자바의 정석 연습문제 6-23 [ 문 제 ] max 메서드 작성기능 : 주어진 int형 배열의 값 중 가장 큰 값을 반환.만일 주어진 배열이 null이거나 크기가 0이면, -999999를 반환.반환타입 : int 매개변수 : int[] arr - 최대값을 구할 배열 class Exercise6_23 { /* (1) max메서드를 작성하시오. */ public static void main(String[] args) { int[] data = {3,2,9,4,7}; System.out.println(java.util.Arrays.toString(data)); System.out.println("최대값:"+max(data)); System.out.println("최대값:"+max(null)); System.out.println("최대값:..
자바의 정석 연습문제 6-4 [ 문 제 ]class exercise { public static void main(String args[]) { Student s = new Student(); s.name = "홍길동"; s.ban = 1; s.no = 1; s.kor = 100; s.eng = 60; s.math = 76; System.out.println("이름 : " + s.name); System.out.println("총점 : " + s.getTotal()); System.out.println("평균 : " + s.getAverage()); } } class Student{ String name; int ban; int no; int kor; int eng; int math; } 출력값 이름 : 홍길동총점 : 236평균 :..
자바의 정석 연습문제 6-2 [ 문 제 ]class Exercise6_2 { public static void main(String args[]) { SutdaCard card1 = new SutdaCard(3, false); SutdaCard card2 = new SutdaCard(); System.out.println(card1.info()); System.out.println(card2.info()); } } class SutdaCard { /* (1) 알맞은 코드를 넣어 완성하시오. */ } 출력값 31K [ 풀 이 ] class exercise { public static void main(String args[]) { SutdaCard card1 = new SutdaCard(3, false); SutdaCard card2..
[안드로이드] 생명주기 1. 액티비티의 일생 생명주기(Life Cycle) : 액티비티가 시작, 실행, 활성, 비활성화 ,정지, 종료되는 일련의 상태를 순환하는데 이것을 생명주기라고 한다. 시스템은 태스크(Task)의 실행 중인 액티비티를 스택(Stack)으로 관리한다. 새 액티비티가 제일 위에 배치되고, 제일 위 액티비티가 종료되면 바로 아래쪽에 있는 액티비티가 활성화된다. 스택(Stack)상 액티비티는 다음과 같은 3가지 상태중 하나이다. 실행(active, running) : 사용자가 직접 사용하는 상태이다. 스택의 제일 위에 있으며 화면상에서도 제일 위에 있다. 입력 포커스를 가지며 사용자의 입력을 직접 처리한다. 정지(stopped) : 다른 액티비티에 의해 가려진 상태이며 사용자 눈에 보이지 않는다. 그러나 정보를 ..
[JAVA] 내부 클래스(inner class) 1. 내부클래스(inner class) 클래스 내에 선언된 클래스 (서로 긴밀한 관계가 있음) 장점 : 내부 클래스에서 외부 클래스의 멤버들을 쉽게 접근할 수 있음 코드의 복잡성을 줄일 수 있음(캡슐화) 2. 내부클래스 종류와 특징 변수의 선언위치에 따라 // 인스턴스 변수, 클래스 변수, 지역변수로 나누는 것처럼클래스의 선언위치에 따라 // 인스턴스 클래스, 스태틱 클래스, 지역 클래스, 익명 클래스로 나뉜다. 3. 내부클래스의 선언 class Outer { class InstanceInner {} // 인스턴스 클래스 static class StaticInner {} // 스태틱 클래스 void myMethod(){ class LocalInner {} // 지역 클래스 } } 4. 내부클래스의 제어자..
자바의 정석 연습문제 9-4 [문제]class Exercise9_4 { static void printGraph(int[] dataArr, char ch) { /* (1) printGraph메서드를 작성하시오. */ } public static void main(String[] args) { printGraph(new int[]{3,7,1,4},'*'); } } [정답] class exercise { static void printGraph(int[] dataArr, char ch) { for( int i = 0; i < dataArr.length; i++) { for (int j = 0 ; j
자바의 정석 연습문제 9-3 [문제] class Exercise9_3 { public static void main(String[] args) { String fullPath = "c:\\jdk1.5\\work\\PathSeparateTest.java"; String path = ""; String fileName = ""; /* (1) 알맞은 코드를 넣어 완성하시오. */ System.out.println("fullPath:"+fullPath); System.out.println("path:"+path); System.out.println("fileName:"+fileName); } } [나의 코드]int index = fullPath.indexOf("work"); path = fullPath.substring(0, index+4..