2016년 7월 19일 화요일

Java 1-5 배열 array


public class Array {

public static void main(String[] args) {

int num1;
int num2;
int num3;
int num4;

// 배열
// 배열은 묶음 그릇의 자료 타입이 모두 같아야 한다.
// 하나의 자료타입으로만 묶음 그릇이 가능하다. >> 나중에 다른 타입도 묶을 수 있는게 나온대..
// 한번 정해진 수납공간의 수는 변경할 수 없다. >> 나중에 변경할 수 있는게 나온대..

// 1. 선언과정
// 2. 초기화
//int[] num;

// int 타입의 6칸짜리 num이라는 이름의 묶음 그릇.
// int[] num; num = {1, 3, 5, 2, 3, 4}; 이런 식으로는 안됨. 에러남. 선언과 동시에 초기화해야함.
int[] num = {1, 3, 5, 2, 3, 4};

int[] numA;
// 2. 생성과정
// 초기화하고는 다르게 해도 된다. new라는 키워드를 이용해서 생성한다.
numA = new int[6];
numA[2] = 10;
int[] numB = numA;
System.out.println("numA[2] = " + numA[2] + ", numB [2] = " +numB[2]);
// 다시 생성할수 있다. 이경우 이전에 생성했던 6칸짜리 방은 없어지고 4칸짜리 방을 새로 만든다.
numA = new int[4];
numA[2] = 77;
System.out.println(numA[2]);

// 3. 사용과정
// 가장 앞에 있는 부분은 0부터 시작한다. 고로 num[2]는 3번째 부분인 5를 가리킨다.
num[2] = num[2] + 5;
System.out.println("3번째 숫자는 " + num[2] + "이다.");


// 반복을 통한 출력
int[] numC = { 11, 22, 33, 44, 55};
for (int i = 0; i < numC.length; i++) {
System.out.println("numC : " + numC[i]);
}

// 다차원 배열도 가능하다.
int[][] numD = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9, 10} // 이렇게 3행만 4열이어도 상관없다.

};
System.out.println(numD[1][1]);
}

}

Java 1-4 제어문 if ,switch,case, 부르마블 주사위


public class If {

public static void main(String[] args) {

int num = 99;
if (num > 15) {
System.out.println("15초과");
}
// if {} else {}
// if {} else if (조건) {} 형태도 가능
else {
System.out.println("15이하");
}


}

}
//부르마블 주사위 던지기
public class IfEx1 {

public static void main(String[] args) {

System.out.println("주사위를 던집니다. 더블이 나오면 다시 던질 수 있습니다.");
//이동거리 정의
int distance = 0;
//무한반복
while (true) {
// 꿀팁 : 특정부분을 밀고싶으면(tab) 블록지정하고 tab누르면 된다.
// dice1,2는 랜덤 주사위값
int dice1 = (int) (Math.random() * 6) + 1;
int dice2 = (int) (Math.random() * 6) + 1;
distance = distance + dice1 + dice2;
if (dice1 == dice2) {
System.out.println("꺄! 더블"+dice1+"이(가) 나왔네요!");
System.out.println("다시 한번 던집니다.");

   } else {
System.out.println(dice1 + ", " + dice2 + " 눈금이 나왔어요.");
break;
}
}
System.out.println("총 이동거리는 "+ distance + "입니다.");

}

}

public class IfEx2 {

public static void main(String[] args) {
// 학점별 분기 코드
float score = 87.5F;
if (score >= 90) {
System.out.println("A학점");
}
//else를 사용하면 앞에서 나온 if의 조건을 제외한 나머지 조건만 적으면 된다.
else if (score >= 80) {
System.out.println("B학점");
}
else if (score >= 70) {
System.out.println("C학점");
}
else if (score >= 60) {
System.out.println("D학점");
}

}

}

public class Switch {

public static void main(String[] args) {

// switch은 조건이 아닌 값 하나를 가지고 분기를 하는 분기문.
int menuCode = 2;
switch (menuCode) {
case 1:
System.out.println("1번 기능");
break;
case 2:
System.out.println("2번 기능");
case 3:
System.out.println("3번 기능");
break;
case 4:
case 5:
System.out.println("4번/5번 기능");
break;
default:
System.out.println("잘못 선택한 기능입니다.");
break;
}
// 값이 1일때 : 1번 기능 수행
// 값이 2일때 : 2번 기능 수행 후 3번 기능 수행
// 값이 3일때 : 3번 기능 수행
// 값이 4일때 : 4/5번 기능 수행
// 값이 5일때 : 4/5번 기능 수행
// 값이 그 외의 값일때 : 잘못 선택한 기능이라고 출력
// 위의 코드를 if문으로 전환하세요
// 5개의 println구문은 더 이상 추가하지 말고, 변경하지 말것 
// 왜?? >> 같은 구문을 복사함으로 복수개 존재하면 유지보수가 어렵다.
// default 구문은 필히 else 구문으로 사용할 것(else if도 사용하지 말라)
// default 구문을 else만으로 처리하기 위해 그에 해당하는 반대조건을 모두 한번에 쓰지 말것
// 왜?? >> 마지막 else는 조건을 안 붙이는 편이 에러를 줄일 수 있다.
if (menuCode == 1) {
System.out.println("1번 기능");
}
else if (menuCode == 2 || menuCode == 3) {

if (menuCode ==2) {
System.out.println("2번 기능");
}
System.out.println("3번 기능");
}
else if (menuCode == 4 || menuCode == 5 ) {
System.out.println("4번/5번 기능");
}
else {
System.out.println("잘못 선택한 기능입니다.");
}
}

}

2016년 7월 17일 일요일

Java 1-3 for문, while문, 구구단 만들기


public class For {

public static void main(String[] args) {

// while입력하고 자동완성(ctrl+space)팝업창에서 3번째 while선택
// condition에서는 조건문(true, false)를 넣어준다.

//while (조건) {
// 반복될 내용들...
// }

// index 변수로 보통 i를 정의한다.
int i=0;
// 진행순서 : 조건 >> 내용 >> 조건 >> 내용 >>반복..
while (i < 3) {
System.out.println("반복될 내용: " + i);
i++; //증감
}

//for (기준값;조건;증감문) {
// 내용..
//}

// 진행순서 : 기준값 >> 조건 >> 내용 >> 증감문 >> 조건 >> 내용 >> 증감문 >> 반복...
// continue를 만나면 continue아래내용를 건너뛰고 증감문으로 넘어간다. 실무에서는 continue를 사용안함
// break를 만나면 걍 끝내기. break문이 속한 for문만 종료한다.
//for (int j=1;j<10;j++){
// System.out.println("7 * " + j + " = " + j*7);
//}

// 구구단 만들기
for (int dan=2 ; dan <= 9 ; dan++){
System.out.println("============ " + dan +"단 ============");
// 조건문은 9바퀴를 돈다는 것을 명확하게 보여주기 위하여 n<10이 아니고 n<=9로 적음
for (int n=1 ; n <= 9 ; n++){
// 변수의 사용범위 : 만들어진 중괄호 블록이 끝날때 사라진다.
int sum = dan * n;
System.out.println(dan + " * " + n + " = " + sum );

}
}



}

}

Java 1-2 연산자, 변수타입, 자동형변환(promotion), 연산자 우선순위

1. 주석
// 주석
/* */ 주석
@ 어노테이션 주석(사람, 시스템에 알려주는 주석)

2. static은 객체 생성없이 사용할 수 있다.
3. 자바는 대소문자 구별한다.
4. 기본 데이터 타입 종류
 > 모두 default는 0이다.(그래서 boolean의 default는 false)
타입.크기(byte)
byte.1
short.2
int.4
long.8
float.4
double.8
char.2
boolean.1
//레퍼런스타입.4(32,64bit 상관없이 4byte).default는 NULL.객체의 주소를 저장하는 변수

5. 계산식에 여러가지 데이터 타입이 섞여있을 경우, 같은 타입으로 맞추어 계산한다.
이를 프로모션이라고 한다. 맞출때는 큰 데이터 타입으로 맞춘다.
(예 : int + float = float )

6. 연산자의 우선순위.연산순서

() 왼쪽에서 오른쪽
++, --, 부호(+,-), ~, !, (cast)  오른쪽에서 왼쪽
*, /, %  왼쪽에서 오른쪽
+, -  왼쪽에서 오른쪽
<<, >>, >>>  왼쪽에서 오른쪽
<, >, <=, >=  왼쪽에서 오른쪽
==, != 왼쪽에서 오른쪽
& 왼쪽에서 오른쪽
^ 왼쪽에서 오른쪽
! 왼쪽에서 오른쪽
&& 왼쪽에서 오른쪽
!! 왼쪽에서 오른쪽
?: 왼쪽에서 오른쪽
=,+=,-=,*=,/=,%= 오른쪽에서 왼쪽

99. 실습
public class Operator {

public static void main(String[] args) {

double result = (2 + 4) * 2;
System.out.println(result);

int intA = 12;
double doubleA = 12;
float floatA = 12;
// >>는 비트를 오른쪽으로 밀어낸다.
// 1100을 오른쪽으로 2칸 밀어내어 0011, 즉 3이 된다.
intA = intA >> 2;
// 실수형은 >> 가 안된다. 에러발생
// doubleA = doubleA>>2;
// floatA = floatA >> 2;
System.out.println(intA+ " " + doubleA + " " + floatA);

System.out.println(intA);
intA++;
System.out.println(intA);

System.out.println(doubleA);
doubleA++;
System.out.println(doubleA);

int a = 6 , b = 2;
boolean result2 = a < b || b == 2;
result2 = !(a < b);
System.out.println("result2: " + result2);

// 삼항연산자 -> 조건 ? 참의값 : 거짓의값
String result3 = a==b ? "같다." : "다르다." ;
System.out.println("a와 b가 " + result3);

// 각종 수학 계산기능이 담겨있는 묶음 기능(클래스)
// Math.random() 은 무작위로 더블값을 준다.
double ra = Math.random();
System.out.println(ra);
// int dice = Math.random() * 범위 + 시작값;
// 값이나 특정 계산식의 앞에 (자료타입) 형태를 붙여주면 강제로 타입이 바뀐다.
int dice = (int)(ra * 6 + 1);
// 주사위의 값과 그값의 2배값을 출력하는 상황
System.out.println("dice: " + dice +
", dice*2: " + dice*2);

}
}

Java 1-1 Hello world! 출력


public class HelloWorld {

public static void main(String[] args) {
// TODO Auto-generated method stub

// 주석 - 설명문
// 출력문 - 원하는 글자를 화면에 출력하는 기능
// 명령문 다치면 귀찮으니까 sysout 이라고 입력하고 >> (컨트로+스페이스) 누르니까 자동완성팝업창 나옴
// >> 거기서 맞는거 고름 >> 괄호안에 출력하고 싶은 글자를 (쌍따옴표""안에)치면 끝~
System.out.println("Hello! World");

}

}

백미당 아이스크림 ★★★★★

@코엑스 현대백화점 백미당
출장갔다 먹은 백미당 소프트아이스크림
우유우유해서 참 맛있다😍
뽀얀 자태 

--------------------------------------------------------------------------------------------------
+2016.11.추가 @수원롯데몰 백미당


파리크라상 망고빙수 ★★

완전우유빙수는 아니고 우유를 조금 넣었고,
망고는 생망고지만 양이 부족하다. 
라지를 시켰는데 그릇만 크고, 우유와 망고 너무 조금이야.

대만서 먹은 망고빙수가 생각나 아쉬웠다. 
망고만 골라먹고 남겼다.
파리크라상 대학로점

대학로 혜화칼국수 ★★★★

응팔에 나온 혜화칼국수
야채는 많이 안들었지만 면이 얇고 맛있다
멸치육수라고하기엔 진하고
사골육수라고하기엔 편안한게
멸치육수에 소고기다시다를 넣은것같은 맛이다. 
아주 자극적이지도 않고, 엄청 자연자연한 맛도 아닌 중용의 맛을 지킨 맛난 칼국수


2016년 7월 16일 토요일

태준제약 코리트산 공략. 대장내시경

대장내시경을 오전에 예약했다면, 전날 저녁부터 장을 비워야 한다.

병원마다 차이가 있는데, 우리동네 성빈센트병원에서는 코리트산을 주었다.

전날 저녁에 4포, 2L

당일 아침에 4포, 2L

코리트산을 검색해보면 쉽지 않은 상대임을 알수 있다..

이에 공략글을 써본다.

준비물 : 코리트산, 사이다, 500ml물통, 추파춥스, 물컵2개

1. 코리트산과 동봉되어있는 500ml 물통에 찬물과 코리트산을 섞는다.
쉐키쉐키... 이때 물의 양은 300~400ml가 적당하다.
주의 : 마시기 15분 전쯤 냉동실에 넣어 아주 차갑게 한다.

2. 평소 즐겨쓰는 머그컵을 준비한다.(250ml정도 용량이 원샷하기 좋다.)

3. 머그컵에 1번 액체를 따른 후, 코를 막고 원샷한다.

4. 마시고 바로 순결한 물로 입을 헹군다.

5. 추파춥스로 고생한 혀에게 달콤함을 준다.

6. 사이다로 입을 헹군다.

7. 물로 다시 입을 헹군다.

8. 1~7과정을 코린트산 8포를 완주할때까지 반복한다.

건투를 빈다...

공략보상 : 디톡스효과가 있는것 같다. 피부가 좋아졌다.




엑셀 하이퍼링크 삭제

엑셀하다가 도메인명을 입력하면 자동으로 하이퍼링크설정이 되어서 짜증난다잉

하이퍼링크를 전체삭제하는 방법은 아래와 같슴다.

1. Alt + F11 >> 비쥬얼베이직 열기

2. Ctrl + G >> 직접실행창 열기

3. cells.hyperlinks.delete 입력하고 엔터
(참고로 영어 앞에 입력하다 보면 아래 관련명령어들이 나오는데 tab키를 누르면 자동입력되요.이건 엑셀 함수칠때도 같은 방식이얌.)

4. 비주얼베이직창닫으면 하이퍼링크 다없어져 있어용

엑셀 쉬프트+엔터 줄바꿈되어있는것 텍스트나누기

텍스트나누기 > 구분기호로 분리됨 > 기타(알트 누르고 10 입력-화면에는 표시안됨) >>다음

엑셀 날짜 차이 계산 함수 datedif

시작
함수
결과
 
2000-01-01
2011-03-05
=DATEDIF(B7,C7,"d")
4081
   일수 계산
 
 
=DATEDIF(B7,C7,"m")
134
   월수 계산
 
 
=DATEDIF(B7,C7,"y")
11
   연수 계산
 
 
=DATEDIF(B7,C7,"yd")
64
   연도 무시, 일수 계산 ( 1월1일 ~ 3월5일 차이 계산)
 
 
=DATEDIF(B7,C7,"ym")
2
   연도 무시, 월수 계산 ( 1월~3월 차이 계산)
 
 
=DATEDIF(B7,C7,"md")
4
   day만 비교(1일~5일 차이 계산)

c언어 자료구조, 배열을 이용한 리스트3(ArrayListTest.cpp)

2009.05.06

배열을 이용한 구조체 파일3가지를 한 프로젝트에 넣어야지 돼용.

*.cpp는 소스에 *.h는 헤더파일에 넣으면 돼용


#include "ArrayList.h"
#include <stdio.h>
void display(ArrayListType *);

// 레포트를 제출할 때는 LIST ADT에 있는 정의되어 있는 모든 operation을 사용하지 예제를 작성하여 제출할 것
void main()
{
 ArrayListType list1;
 ArrayListType *plist;
 init(&list1);
 add(&list1, 0, 10);
 add(&list1, 0, 20);
 add(&list1, 0, 30);
 add_first(&list1, 1777);
 add_last(&list1, 7777);
 remove(&list1,1);
 display(&list1);
 printf("\n\n       is_*()함수를 test합니다.\n");
 printf("\n혹시 list1이 텅 비어있나요??\n");
 ans(is_empty(&list1));
 printf("혹시 list1이 꽉 찼나요??\n");
 ans(is_full(&list1));

 plist = (ArrayListType *)malloc(sizeof(ArrayListType));
 init(plist);
 add(plist, 0, 10);
 add(plist, 0, 20);
 add(plist, 0, 30);
 add_last(plist,9056);
 add_last(plist,6291);
 replace(plist,2 ,22 );
 printf("\n\n       position에 관련된 함수를 test합니다.\n\n");
 printf("plist의 맨앞에는 %d이(가) 있습니다.\n",plist->list[first(plist)]);
 printf("plist의 맨뒤에는 %d이(가) 있습니다.\n",plist->list[last(plist)]);
 printf("plist[2]에는 %d이(가) 있습니다.\n",get_entry(plist,2));
 printf("plist[2] 앞에는 %d이(가) 있습니다.\n",plist->list[before(plist,2)]);
 printf("plist[2] 뒤에는 %d이(가) 있습니다.\n",plist->list[after(plist,2)]);

 printf("\n\n       clear(plist)전의 출력결과.\n\n");
 display(plist);
 printf("plist에 9056이 있습니까?\n");
 ans(is_in_list(plist,9056));
 printf("plist의 길이는 %d입니다.\n",get_length(plist));
 clear(plist);
 printf("\n\n       clear(plist)후의 출력결과.\n\n");
 display(plist);
 printf("plist에 9056이 있습니까?\n");
 ans(is_in_list(plist,9056));
 printf("plist의 길이는 %d입니다.\n",get_length(plist));

 error("\n\n끝~~");
}
void display(ArrayListType *L)
{
 position idx;
 if(is_empty(L)){
  printf("list is empty");
  return;
 }

 printf("folowing items are stored in List\n");
 for(idx = first(L); idx <= last(L); idx++){
  printf("%d  ", get_entry(L, idx));
 }
 printf("\n");
}

c언어 자료구조 - 배열을 이용한 리스트2 (ArrayList.h )

2009.05.06

#pragma once
#include <stdio.h>
#include <stdlib.h>
#define MAX_LIST_SIZE 100
typedef int element;
typedef int position;
typedef struct{
 int list[MAX_LIST_SIZE];
 int length;
} ArrayListType;
void error(char *);
void init(ArrayListType *);
int is_empty(ArrayListType *);
int is_full(ArrayListType *);
void add(ArrayListType *, position, element);
//delete 대신 remove로 바꿈 <-- cpp에서는 delete 연산자가 정의되어 있기 때문에
element remove(ArrayListType *, position);
element get_entry(ArrayListType *, position);
position first(ArrayListType *);
position last(ArrayListType *);
position before(ArrayListType *, position);
position after(ArrayListType *, position);


void add_last(ArrayListType *, element );
void add_first(ArrayListType *, element);
void clear(ArrayListType *);
void replace(ArrayListType *, position , element );
int is_in_list(ArrayListType *, element );
int get_length(ArrayListType *);
void ans(int);

c언어 자료구조 -배열을 이용한 리스트1 (ArrayList.cpp )

2009.05.06

#include "ArrayList.h"
void error(char *message)
{
 fprintf(stderr,"%s\n", message);
 exit(1); // exit 추가
}
void init(ArrayListType *L)
{
 L->length = 0;
}
int is_empty(ArrayListType *L)
{
 return L->length == 0;
}
int is_full(ArrayListType *L)
{
 return L->length == MAX_LIST_SIZE;
}
void add(ArrayListType *L, position pos, element item)
{
 int i;
 if(!is_full(L) && (pos >= 0) && (pos <= L->length)){
  for(i = (L->length - 1); i >= pos; i--){
   L->list[i+1] = L->list[i];
  }
  L->list[pos] = item;
  L->length++;
 }
}
element remove(ArrayListType *L, position pos)
{
 int i;
 element item;
 if(pos < 0 || pos >= L->length){
  error("위치오류");
 }
 item = L->list[pos];
 for(i = pos; i < last(L); i++){
  L->list[i] = L->list[i+1];
 }
 L->length--;
 return item;
}
position first(ArrayListType *L)
{
 if(is_empty(L)){
  error("list is empty");
  return -1;
 }
 return 0;
}
position last(ArrayListType *L)
{
 if(is_empty(L)){
  error("list is empty");
  return -1;
 }
 return L->length - 1;
}
position before(ArrayListType *L, position pos)
{
 if(is_empty(L)){
  error("list is empty");
  return -1;
 }

 if(pos == first(L)){
  error("current position is first");
  return -1;
 }
 return pos - 1;
}
position after(ArrayListType *L, position pos)
{
 if(is_empty(L)){
  error("list is empty");
  return -1;
 }

 if(pos == last(L)){
  error("current position is last");
  return -1;
 }
 return pos + 1;
}
element get_entry(ArrayListType *L, position pos)
{
 if(is_empty(L) || (pos < first(L)) || (pos > last(L))){
  error("position is out of range");
  return -1;
 }
 return L->list[pos];
}
  void add_last(ArrayListType *L, element item)
{
 add(L,L->length,item);
 
}
       //add_first(list, item) ::= 맨끝에 요소를 추가한다.
void add_first(ArrayListType *L, element item)
{
 add(L,0,item);
 

}
       //clear(list) ::= 리스트의 모든 요소를 제거한다.
void clear(ArrayListType *L)
{
 L->length=NULL;
 free(L->list);

}
       //replace(list, pos, item) ::= pos 위치의 요소를 item로 바꾼다
void replace(ArrayListType *L, position pos, element item)
{
 L->list[pos]=item;

}
       //is_in_list(list, item) ::= item이 리스트안에 있는지를 검사한다.
int is_in_list(ArrayListType *L, element wts)
{
 int i;
 for(i=0;i<L->length;i++){
  if(L->list[i]==wts){
   return 1;}}
 return 0;
}

       //get_length(list) ::= 리스트의 길이를 구한다.
int get_length(ArrayListType *L)
{
 return L->length;
}
void ans(int n)
{
 if(n){
  printf("예!!!그렇습니다!!\n");}
 else{
  printf("아니요... 그렇지 않습니당...\n");}
}

c언어 자료구조론 - 다항식의 덧셈

2009.04.26.

#include <stdio.h>
typedef struct{
 int deg;
 int po[10];
}poly;
poly p_add(poly a,poly b){
 poly c;
 int ap=0,bp=0,cp=0;
 int ai=a.deg,bi=b.deg;
 while(ap<=a.deg && bp<=b.deg){
  if(ai>bi){
   c.deg=a.deg;
   c.po[cp++]=a.po[ap++];
   ai--;}
 
  else if(ai<bi){
   c.deg=b.deg;
   c.po[cp++]=b.po[bp++];
   bi--;}
  else{
   c.deg=a.deg;
   c.po[cp++]=a.po[ap++]+b.po[bp++];}
 }
 return c;
}
void main(){
 poly a={3,{1,2,3,4}};
 poly b={2,{  1,2,3}};
 
 poly ans=p_add(a,b);
 int i=ans.deg;
 int p=0;
 for(;i>1;i--){
  printf("%dX^%d  +  ",ans.po[p],i);
  p++;}
 printf("%dX  +  %d\n",ans.po[p],ans.po[p+1]);

}

c언어 자료구조론 - 피보나치수열2 (구조체사용)

2009-04-26

high-ordered recursion으로 구성되어 시간복잡도가 컸던 함수를

이전 게시글에 있는 피보나치수열과 마찬가지로 linear recursion으로 구성한것이에용.

이전과는 다르게 구조체를 사용하여 표현하였습니다.


#include <stdio.h>
typedef struct{
 int n0;
 int n1;
}Two;   // 구조체선언할때도 ;를 붙이는구낭...

Two fib(int n){

 Two bef;
 Two pre;

 if(n<2){
  bef.n0=0;
  bef.n1=1;
  return bef;}   // }뒤에 ;있어도 같은결과를 출력
 bef=fib(n-1);
 pre.n0=bef.n1;
 pre.n1=bef.n0+bef.n1;
 return pre;}

void main(){
 int n;
 Two tem;
 printf("피보나치수열의 n번째항을 구해드립니당.\nn을 입력하세요.\n");
 scanf("%d",&n);
 tem=fib(n);
 printf("피보나치수열의 %d번째 항은 %d입나다.^3^\n",n,tem.n1);
}

c언어 피보나치수열

2009.04.06작성

재귀함수를 사용한 피보나치 수열이당.

binary recursion으로 작성된 피보나치 함수의 비효율성을 개선한 Linear recursion 방식의 피보나치 함수를 작성하고

피보나치값을 구해서 출력하는 프로그램 작성하는 과제였다.

사실 구조체를 이용하여 구하고 싶었는데 구조체에 대한 공부가 부족하고 제출기한이 다가와서 if를 사용했다 ㅠㅠ

#include<stdio.h>

void fib(int n, int a, int b, int t);
void main()
{
int n,a=1,b=0,t=0;

printf("피보나치수열의 알고싶은 항을 입력하세용! \n");
printf("n번째 항과 n-1번째 항이 순서대로 출력됩니다^3^ \n");
scanf("%d",&n);

fib(n,a,b,t);

return;
}

void fib(int n, int a, int b, int t)
{
 if(n==1) {
  printf("(%d,%d)\n",a,b);
  return;}
 if(n<0) {
  a=0;
  printf("(%d,%d)\n",a,b);
  return;}
 t=a;
 a=a+b;
 b=t;

 fib(n-1,a,b,t);
 return;
}

unix apache 유닉스 아파치 동시접속자수 확인

##유닉스 아파치 동시접속자수 확인 unix apache

# netstat -an | grep .80 | grep -i estab | wc -l

포트명이 리눅스는 :80, 유닉스는 .80으로 표시된다.
netstat 
-a udp포함 모든 접속
-n 숫자 출력
grep
-i 대소문자 무시
wc -l : 라인수 출력

윈도우7 cmd -> ipconfig 가 안 되는 경우

1. 시작 > 환경변수 입력

2. "시스템 환경 변수 편집" 클릭

3. "고급" 탭의 "환경변수" 클릭

4. "시스템 변수" 의 "Path" 확인, %SystemRoot%\System32; 추가하고 확인

5. (cmd창 열려있다면 닫고) 시작 cmd 입력 >> ipconfig >> 나옴 >> 굿

덧붙임>>  "ipconfig/flushdns" 치면 dns 초기화(인터넷이 ㅣ빨라질 수 있음)

java SQLite-jdbc 연결하기 // jar파일 연결하기

1. sqlite-jdbc-3.8.10.1 다운
- 다운 받으면 jar파일이다.
- 이 jar파일을 이클립스를 이용해 연결한다.
- 나중에 백업할 때나 프로젝트를 이동할때 jar파일이 누락되는 것을 방지하고자, jar파일을 프로젝트안에 ext라는 폴더안에 넣어두자.

2. jar 연결(이클립스)
 - 프로젝트 우클릭하여 properties 선택
 - java build path -> libraries -> add external jars 선택
 - 추가하고픈 jar파일 선택
 - ok 선택
 - 끝.

3. sample.java 을 이용해서 연습해보자.

- 생성한 db파일은 파이어폭스 확장 프로그램인 sqlite로 보기좋게 열수 있다.

------------------------------------------------------------------------------------------------------
code
------------------------------------------------------------------------------------------------------

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document; //웹표준, Documnet
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;



public class MainEx2 {

public static void main(String[] args) {
//  네이버 오픈 api로 xml 연결하는걸 연습하자
String strUrl =  "http://openapi.naver.com/search?key=c1b406b32dbbbbeee5f2a36ddc14067f&query=%EC%A3%BC%EC%8B%9D&target=news&start=1&display=10";
//  InputStream 나중에 닫아야돼 
InputStream is =null;
try {
URL url = new URL(strUrl);
// URLConnection 이용하여 웹페이지와 연결
URLConnection conn =  url.openConnection();
is = conn.getInputStream();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} // try~catch
//  InputStream 으로 값을 XML 기능으로 파싱해오는 과정
//         싱글톤
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = null ;
if(is != null) doc = db.parse(is);
if(doc != null) {
// item 노드들을 불러오기
NodeList list = doc.getElementsByTagName("item");
System.out.println("itemCount : " + list.getLength());
// item노드 첫번째 가져오기
Node node = list.item(0);
// 첫번째 item 노드내의 노드들을 가져오기
NodeList itemLists = node.getChildNodes();
System.out.println("itemListsCount : " + itemLists.getLength());
// 첫번째 item노드의 첫번째 노드를 불러오기(타이틀)
Node titleNode =  itemLists.item(0);
System.out.println("Title : " + titleNode.getTextContent());
} // if
} catch (ParserConfigurationException e) {
e.printStackTrace();
}  catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} // try~catch
if(is != null){
    try { is.close();
} catch (IOException e) { e.printStackTrace();
} // try~catch
}  // if

} //main

} // class