이너클래스란 클래스 안의 클래스를 말한다.이너클래스는 아우터클래스의 모든 것을 사용할 수 있지만,아우터클래스가 이너클래스를 사용하려면 먼저, 객체를 생성하고 자신의 객체 참조변수를 시작으로이너클래스의 멤버변수와 메소드를 참조해야한다. public class Outer { int a; public Outer() {System.out.println("아우터 생성자");} public void test() {System.out.println("test call");} public class Inner {int b; public Inner() {System.out.println("Inner class creator" + "\na's value : " + a);test(); //이너클래스는 아우터 클래스의 변수나..
C언어의 printf 함수와 동일한 기능을 하는 printf 메소드 사용%d 구문을 사용하면 글자 간격을 설정할 수 있다. public class gugudan { public static void main(String[] args) {// TODO Auto-generated method stubint result; for (int i = 1; i < 10; i++) {for (int j = 2; j < 10; j++) {result = j * i;System.out.printf("%d*%d = %2d ",j,i,result);}System.out.println();}}}
2~n까지의 수 중에서 소수를 판별하고 개수를 출력한다.for1 : 1은 제외하고 2부터 n까지 반복for2 : 2부터 i까지 모듈러 연산을 통해 소수인지 판별안쪽 반복문 종료 후 break 문으로인한 종료가 아니라 정상 종료라면 소수 public class Prime { public static void main(String[] args) {// TODO Auto-generated method stub int prime = 0;int n = 1000, j; //n은 1000으로 설정 for (int i = 2; i < n; i++) { for (j = 2; j < i; j++) {if (i % j == 0) {break;}}if (i == j) {prime++;System.out.println(i);}..
윈도우 띄우고 그림 그리기 import java.awt.Graphics; import javax.swing.JFrame; public class GraphicTest extends JFrame{ public GraphicTest(String str){super(str);setSize(500,500); //창 크기setLocation(300,300); //창 위치setVisible(true); //창 보이기}public void paint(Graphics g){g.drawLine(10, 10, 190, 190); //직선g.drawRect(10,10,100,100); //사각형g.drawOval(50,50,100,100); //원g.drawArc(100, 100, 80, 80, 0, 90); //호}pub..
재귀함수 이용 import java.util.Scanner; public class FiboTest { public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("피보나치 위치 입력 : ");Scanner scan = new Scanner(System.in);long n = scan.nextInt();System.out.println("fibo[" + n + "] = " + fibo(n));} static long fibo(long n) {// TODO Auto-generated method stubif (n == 1 || n == 2)return 1;elsereturn fibo(n - 1) + ..
class Vehicle {int speed; void drive() {};void stop() {};} public class AirPlane extends Vehicle {int height; void takeOff() {};void landing() {}; public static void main(String arg[]) {AirPlane ap1 = new Vehicle(); //에러 부모 -> 자식간 인스턴스 할당 불가, 형변환 생략불가AirPlane ap2 = (AirPlane) new Vehicle(); // 강제 형변환 Vehicle v1 = new AirPlane(); //정상적인 코드, 형변환 생략가능Vehicle v2 = (Vehicle) new AirPlane(); // 강제 형변환..
package afternoon; public class Factorial { static int num = 5;public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("factorial "+num+" = "+factorial(num));} private static long factorial(int i) {// TODO Auto-generated method stubif(i==1)return 1;elsereturn i * factorial(i-1);}}
클래스 변수는 해당 클래스가 공통으로 사용하는 변수를 말하며 인스턴스 변수에 static 예약어를 사용한다. //클래스 변수를 이용한 제목을 지정하지 않은 문서의 번호 매기기package afternoon; public class DocumentTest { public static void main(String[] args) {// TODO Auto-generated method stubDocument dc = new Document();Document dd = new Document("Class Define");Document de = new Document();Document df = new Document("Serial Test");Document dg = new Document();Document..
- Total
- Today
- Yesterday
- jsp
- CSS
- 아두이노
- 자바스크립트
- 배열
- 청주
- 프로젝트
- 데이터베이스
- 자바
- HTML
- 오라클
- 게임
- 정렬
- 졸업작품
- 클래스
- ERP
- 메모장
- SVN
- db
- JQuery
- 정보
- SQL
- 이론
- 알고리즘
- 잡담
- 안드로이드
- 충북대
- 파이썬
- 소켓
- 도전과제
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |