1 0 1.7 6 5 'A ' '/ u 4 4 2 2 ' " JS P 프로그래밍 "
A ', 'b ', ' 한 ', 9, \ u d 6 5 4 ' c h a r a = 'A '; 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > 유니코드예제 < / title > < / h e a d > < b o d y > < % c h a r a = 'A '; o u t.p rin tln ((in t)a + " < b r/> " ); o u t.p rin tln ((c h a r)6 5 + " < b r/> " ); o u t.p rin tln ((c h a r)0 x 0 0 4 1 + " < b r/> " ); o u t.p rin tln ('\ u 0 0 4 1 ' + " < b r/ > " ); o u t.p rin tln (" < h r/> " ); o u t.p rin tln ((in t)' 가 ' + " < b r/> " ); o u t.p rin tln ((c h a r)0 x A C 0 0 + " < b r/> " ); o u t.p rin tln ('\ u A C 0 0 ' + " < b r/ > " ); % > < / b o d y > < / h tm l>
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > 특수문자예제 < / title > < / h e a d > < b o d y > < % o u t.p rin tln (" \ n 줄바꿈 \ n \ n 기능을테스트합니다.< b r/> " ); o u t.p rin tln (" \ t 탭기능을 \ t 테 \ t 스트합니다 < b r/ > " ); o u t.p rin tln (" 캐리지리턴을 \ r 테스트합니다.< b r/> " ); o u t.p rin tln (" \ ' 작은따옴표를테스트합니다.\ '< b r/> " ); o u t.p rin tln (" \ " 큰따옴표를테스트합니다.\ " " ); % > < / b o d y > < / h tm l>
< h tm l> < h e a d > < title > 특수문자예제 < / title > < / h e a d > < b o d y > 줄바꿈 기능을테스트합니다.< b r/ > 탭기능을 테 스트합니다 < b r/ > 캐리지리턴을테스트합니다.< b r/> ' 작은따옴표를테스트합니다.'< b r/ > " 큰따옴표를테스트합니다." < / b o d y > < / h tm l> in t a 1 = 1 0, b 1 = 1 0 0 0, c 1 = - 2 3 4 ; lo n g a 2 = 1 2 3 4 5 6 7 8 9 0 L, b 2 = 2 3 4 5 l; b y te a 3 = (b y te )1 0 ; s h o rt a 4 = (s h o rt)1 0 0 ;
flo a t a = 1 2 3.2 ; (X ) / / T y p e m is m a tc h : c a n n o t c o n v e rt fro m d o u b le to flo a t flo a t a = 1 2 3.2 F ; (O ) flo a t a = 1 2 3.2 f; (O ) d o u b le a = 1 2 3.2 ; (O ) 1.2 9 9 e 2 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > 실수타입예제 < / title > < / h e a d > < b o d y > < % d o u b le a = 9.9 9 9 9 e 3 ; d o u b le b = 9.9 9 9 9 e 3 0 0 ; % > 변수 a 출력 : < % = a % > < b r/> 변수 b 출력 : < % = b % > < / b o d y > < / h tm l>
tru e, fa ls e 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > b o o le a n 타입예제 < / title > < / h e a d > < b o d y > < % b o o le a n fla g = tru e ; in t i = 1 ; w h ile (fla g ) { o u t.p rin tln (i + " : " + " H e llo J S P! < b r/> " ); i+ + ; if (i = = 1 0 ) fla g = fa ls e ; % > < / b o d y > < / h tm l>
in t v a lu e 1 = 1.2 9 ; (X ) / / in t 타입 v a lu e 1 변수에 d o u b le 타입값할당 flo a t v a lu e 2 = 3.6 7 ; (X ) / / flo a t 타입 v a lu e 2 변수에 d o u b le 타입값할당 s h o rt v a lu e 3 = 3 2 7 6 8 ; (X ) / / s h o rt 타입 v a lu e 3 변수에는 - 3 2 7 6 8 ~ 3 2 7 6 7 인정수값만할당가능 b y te v a lu e 4 = 1 2 8 ; (X ) / / b y te 타입 v a lu e 4 변수에는 - 1 2 8 ~ 1 2 7 인정수값만할당가능 b y te < s h o rt < in t < lo n g < flo a t < d o u b le
lo n g v a lu e 1 = 1 0 0 ; d o u b le v a lu e 2 = 1 0 0 ; / / in t 타입값을묵시적으로 lo n g 타입변수에할당가능 / / in t 타입값을묵시적으로 d o u b le 타입변수에할당가능 d o u b le v a lu e 3 = 2 + 3 ; / / in t 타입연산결과를 d o u b le 타입변수로할당가능 lo n g v a lu e 1 = 1 0 0 L ; / / lo n g 타입값을 lo n g 타입변수에할당 ( 타입변환없음 ) in t v a lu e 2 = (in t)v a lu e 1 ; / / lo n g 타입값을명시적으로 in t 타입변수에할당 in t v a lu e 3 = (in t)5 0 0.4 5 ; d o u b le d = 9.9 9 ; in t v a lu e 4 = (in t)d ;
C a r a = n e w C a r(" 흰색 ", " 4 0 너 4 8 3 7 ", 2 0 0 5, x ); C a r b = n e w C a r(" 검정색 ", " 3 0 겨 1 2 8 7 ", 2 0 0 8, y );
a.c h a n g e G e a r(3 );
< m o d ifie r> p u b lic c la s s [C la s s n a m e ] < e x te n d s S u p e rc la s s n a m e > < im p le m e n ts In te rfa c e (, In te rfa c e )> { / / 멤버변수정의... / / 생성자정의... / / 메소드정의...
p u b lic c la s s P o in t { / / 멤버변수정의 in t x, y ; / / 생성자정의 p u b lic P o in t() { x = 0 ; y = 0 ; p u b lic P o in t(in t x, in t y ) { th is.x = x ; th is.y = y ; / / 멤버메소드정의 p u b lic v o id s e tx (in t x V a lu e ) { x = x V a lu e ; p u b lic v o id s e ty (in t y V a lu e ) { y = y V a lu e ; p u b lic in t g e tx () { re tu rn x ; p u b lic in t g e ty () { re tu rn y ; p u b lic v o id m o v e (in t x V a lu e, in t y V a lu e ) { x + = x V a lu e ; y + = y V a lu e ;
P o in t p = n e w P o in t(); P o in t q = n e w P o in t(1,2 ); P o in t r; r= n e w P o in t(1 0,2 0 );
p u b lic P o in t(in t x V a lu e, in t y V a lu e ) { x = x V a lu e ; y = y V a lu e ; p u b lic c la s s C o lo rp o in t e x te n d s P o in t{ / / 멤버변수정의 S trin g c o lo r; / / 생성자정의 p u b lic C o lo rp o in t() { c o lo r = " b la c k " ; p u b lic C o lo rp o in t(s trin g c o lo r) { th is.c o lo r = c o lo r; / / 멤버메소드정의 p u b lic v o id s e tc o lo r(s trin g c o lo rv a lu e ) { c o lo r = c o lo rv a lu e ; p u b lic S trin g g e tc o lo r() { re tu rn c o lo r;
C o lo rp o in t c p = n e w C o lo rp o in t(); c p.g e tx (); c p.g e ty (); c p.m o v e (1 0 0,2 0 0 );
p u b lic c la s s C o lo rp o in t e x te n d s P o in t{ / / 멤버변수정의 S trin g c o lo r;... v o id m o v e (in t x V a lu e, in t y V a lu e ) { x + = x V a lu e ; y + = y V a lu e ; c o lo r = " b la c k "
p u b lic c la s s C o lo rp o in t e x te n d s P o in t{ / / 멤버변수정의 S trin g c o lo r;... p u b lic v o id m o v e (in t x V a lu e, in t y V a lu e ) { x + = x V a lu e ; y + = y V a lu e ; c o lo r = " b la c k " p u b lic v o id m o v e (in t v a lu e ) { x + = v a lu e ; y + = v a lu e ; p u b lic c la s s P o in t { / / 정적변수정의 s ta tic in t n u m = 0 ;... / / 생성자정의 p u b lic P o in t() { x = 0 ; y = 0 ; n u m + + ; p u b lic P o in t(in t x, in t y ) { th is.x = x ; th is.y = y ; n u m + + ; / / 정정메소드정의 p u b lic s ta tic in t g e tin s ta n c e N u m () { re tu rn n u m ;
P o in t p 1 = n e w P o in t(); P o in t p 2 = n e w P o in t(1 0 0,2 0 0 ); o u t.p rin tln (P o in t.g e tin s ta n c e N u m ()); / / 2 출력
C a le n d a r c a l = C a le n d a r.g e tin s ta n c e ();
p a c k a g e th in k o n w e b.lib ; p u b lic c la s s P o in t { / / 멤버변수정의 in t x, y ; / / 생성자정의 p u b lic P o in t() { x = 0 ; y = 0 ;... th in k o n w e b.lib.p o in t p 1 = n e w th in k o n w e b.lib.p o in t(); th in k o n w e b.lib.p o in t p 2 = n e w th in k o n w e b.lib.p o in t(1 0 0,2 0 0 ); im p o rt th in k o n w e b.lib.p o in t; P o in t p 1 = n e w P o in t(); P o in t p 2 = n e w P o in t(1 0 0,2 0 0 );
im p o rt th in k o n w e b.lib.* ; P o in t p 1 = n e w P o in t(); P o in t p 2 = n e w P o in t(1 0 0,2 0 0 );
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 p a c k a g e th in k o n w e b.lib ; p u b lic c la s s P o in t { s ta tic in t n u m ; in t x, y ; p u b lic P o in t() { x = 0 ; y = 0 ; n u m + + ; p u b lic P o in t(in t x, in t y ) { th is.x = x ; th is.y = y ; n u m + + ; p u b lic v o id s e tx (in t x V a lu e ) { x = x V a lu e ; p u b lic v o id s e ty (in t y V a lu e ) { y = y V a lu e ; p u b lic in t g e tx () { re tu rn x ; p u b lic in t g e ty () { re tu rn y ; p u b lic v o id m o v e (in t x V a lu e, in t y V a lu e ) { x + = x V a lu e ; y + = y V a lu e ; p u b lic s ta tic in t g e tin s ta n c e N u m () { re tu rn n u m ;
S trin g a ; S trin g b = n u ll; S trin g c = " H e llo " ; D a te d = n e w D a te (); C a le n d a r e = C a le n d a r.g e tin s ta n c e ();
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < % @ p a g e im p o rt= " th in k o n w e b.lib.* " % > < h tm l> < h e a d > < title > 레퍼런스데이터타입테스트 < / title > < / h e a d > < b o d y > < % P o in t p 1 = n e w P o in t(); P o in t p 2 = n e w P o in t(1 0, 2 0 ); % > T h e n u m b e r o f P o in t in s ta n c e s : < % = P o in t.g e tin s ta n c e N u m ()% > < b r/> p 1 's x : < % = p 1.g e tx () % > < b r/> p 1 's y : < % = p 1.g e ty () % > < b r/> p 2 's x : < % = p 2.g e tx () % > < b r/> p 2 's y : < % = p 2.g e ty () % > < b r/> < % p 1.m o v e (1 0 0,2 0 0 ); % > p 1 's x : < % = p 1.g e tx () % > < b r/> p 1 's y : < % = p 1.g e ty () % > < b r/> < / b o d y > < / h tm l>
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > 배열테스트 < / title > < / h e a d > < b o d y > < % in t[] fib o n a c c i = n e w in t[5 ]; in t le n g th A rra y ; fib o n a c c i[0 ] = 0 ; fib o n a c c i[1 ] = 1 ; fib o n a c c i[2 ] = fib o n a c c i[0 ] + fib o n a c c i[1 ]; fib o n a c c i[3 ] = fib o n a c c i[1 ] + fib o n a c c i[2 ]; fib o n a c c i[4 ] = fib o n a c c i[2 ] + fib o n a c c i[3 ]; le n g th A rra y = fib o n a c c i.le n g th ; % > fib o n a c c i 배열의내용 : < % fo r (in t i = 0 ; i < 5 ; i+ + ) { % > < % = fib o n a c c i[i] % > < % % > < b r/> fib o n a c c i 배열의길이 : < % = le n g th A rra y % > < b r/> < / b o d y > < / h tm l>
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > 수치연산자예 < / title > < / h e a d > < b o d y > < % in t o p e ra n d 1 = 8 ; in t o p e ra n d 2 = 3 ; o u t.p rin tln (o p e ra n d 1 + " + " + o p e ra n d 2 + " = " + (o p e ra n d 1 + o p e ra n d 2 ) + " < b r/> " ); o u t.p rin tln (o p e ra n d 1 + " - " + o p e ra n d 2 + " = " + (o p e ra n d 1 - o p e ra n d 2 ) + " < b r/> " ); o u t.p rin tln (o p e ra n d 1 + " * " + o p e ra n d 2 + " = " + (o p e ra n d 1 * o p e ra n d 2 ) + " < b r/ > " ); o u t.p rin tln (o p e ra n d 1 + " / " + o p e ra n d 2 + " = " + (o p e ra n d 1 / o p e ra n d 2 ) + " < b r/> " ); o u t.p rin tln (o p e ra n d 1 + " % " + o p e ra n d 2 + " = " + (o p e ra n d 1 % o p e ra n d 2 ) + " < b r/> " ); % > < / b o d y > < / h tm l>
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > + + 및 - - 연산자사용 < / title > < / h e a d > < b o d y > < % in t i = 0 ; in t j = 0 ; % > 첫번째 i 값 = < % = i+ + % > < b r/> 두번째 i 값 = < % = i % > < b r/> 세번째 i 값 = < % = + + i % > < b r/> 네번째 i 값 = < % = i % > < h r/> 첫번째 j 값 = < % = j- - % > < b r/> 두번째 j 값 = < % = j % > < b r/> 세번째 j 값 = < % = - - j % > < b r/> 네번째 j 값 = < % = j % > < / b o d y > < / h tm l>
A > = 1 & & A < 1 0 0
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > 논리연산자 < / title > < / h e a d > < b o d y > < % in t i = 0 ; in t j = 1 ; if(+ + i= = j & & + + i= = + + j) o u t.p rin tln (" tru e < b r/ > " ); % > i 값 = < % = i % > < b r> j 값 = < % = j % > < b r> < % if(+ + i= = + + j + + i= = j) o u t.p rin tln (" tru e < b r/> " ); % > i 값 = < % = i % > < b r> j 값 = < % = j % > < / b o d y > < / h tm l>
if ( 조건 ) { 코드 ; / / 조건비교의결과값이참 (tru e ) 인경우에코드를수행 if ( 조건 ) { 코드 1 ; e ls e { 코드 2 ; / / 조건이참 (tru e ) 인경우에수행 / / 조건이거짓 (fa ls e ) 일경우에수행 if ( 조건 1 ) { 코드 1 ; / / 조건 1 이참 (tru e ) 인경우에수행 e ls e if ( 조건 2 ) { 코드 2 ; / / 조건 1 이거짓 (fa ls e ) 이고조건 2 가참 (tru e ) 인경우에수행 e ls e { 코드 3 ; / / 조건 1 과조건 2 가모두거짓 (fa ls e ) 인경우에수행
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > if 문 < / title > < / h e a d > < b o d y > < % in t n u m = 5 ; o u t.p rin t(" n u m = " ); if(n u m = = 2 ) { o u t.p rin tln (" 2 " ); e ls e if(n u m = = 5 ) o u t.p rin tln (" 5 " ); e ls e { o u t.p rin tln (" n u ll" ); % > < / h tm l>
s w itc h ( 조건식 ) { c a s e 상수 1 : 문장 1 ; b re a k ; c a s e 상수 2 : 문장 2 ; b re a k ; c a s e 상수 n : 문장 n ; b re a k ; d e fa u lt : 문장 ;
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > s w itc h 문 < / title > < / h e a d > < b o d y > < % in t n u m = 1 2 / 3 ; o u t.p rin t(" n u m = " ); s w itc h (n u m ){ c a s e 1 : o u t.p rin tln (" 1 " ); b re a k ; c a s e 2 : o u t.p rin tln (" 2 " ); b re a k ; c a s e 4 : o u t.p rin tln (" 4 " ); b re a k ; d e fa u lt: o u t.p rin tln (" d e fa u lt" ); b re a k ; % > < / h tm l>
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > s w itc h 문활용예제 < / title > < / h e a d > < b o d y > < % in t m o n th = 2 ; in t y e a r = 2 0 0 9 ; in t n u m D a y s = 0 ; s w itc h (m o n th ) { c a s e 1 : c a s e 3 : c a s e 5 : c a s e 7 : c a s e 8 : c a s e 1 0 : c a s e 1 2 : n u m D a y s = 3 1 ; b re a k ; c a s e 4 : c a s e 6 : c a s e 9 : c a s e 1 1 : n u m D a y s = 3 0 ; b re a k ; c a s e 2 : if ( ((y e a r % 4 = = 0 ) & &!(y e a r % 1 0 0 = = 0 )) (y e a r % 4 0 0 = = 0 ) ) n u m D a y s = 2 9 ; e ls e n u m D a y s = 2 8 ; b re a k ; d e fa u lt: b re a k ; % > < % = y e a r % > 년 < % = m o n th % > 의총일수는 < % = n u m D a y s % > 일입니다. < / h tm l>
fo r ( 초기값 ; 조건식 ; 증감식 ){ 반복할문장 ; / / 조건식이참인경우에수행
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > fo r 문을이용한구구단 2 단 < / title > < / h e a d > < b o d y > < % in t i = 2 ; fo r(in t j= 1 ; j< 1 0 ; j+ + ){ o u t.p rin tln (i + " * " + j + " = " + (i* j) + " < b r/> " ); % > < / h tm l>
w h ile ( 조건식 ) { 반복할문장 ; / / 조건식이참인경우에수행 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > w h ile 문을이용한구구단 5 단 < / title > < / h e a d > < b o d y > < % in t i = 5 ; in t j = 1 ; w h ile (j< 1 0 ) { o u t.p rin tln (i + " * " + j + " = " + (i* j) + " < b r/> " ); j+ + ; % > < / h tm l>
d o { 반복할문장 ; / / 한번수행후조건식이참인경우에수행 w h ile ( 조건식 ); 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > d o ~ w h ile 문을이용한구구단 9 단 < / title > < / h e a d > < b o d y > < % in t i = 9 ; in t j = 1 ; d o { o u t.p rin tln (i + " * " + j + " = " + (i* j) + " < b r/> " ); j+ + ; w h ile (j< 1 0 ); % > < / h tm l>
w h ile ( 조건식 1 ) {... if ( 조건식 2 ) b re a k ;... 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < % @ p a g e im p o rt = " ja v a.u til.r a n d o m " % > < h tm l> < h e a d > < title > b re a k 예 < / title > < / h e a d > < b o d y > < % R a n d o m ra n d o m = n e w R a n d o m (); fo r (in t i = 1 ; i < = 1 0 ; i+ + ) { in t n u m b e r = ra n d o m.n e x tin t(1 0 ) + 1 ; o u t.p rin tln (i + " 번째값 : " + n u m b e r + " < b r/> " ); if (n u m b e r = = 5 ) b re a k ; % > < / b o d y > < / h tm l>
w h ile ( 조건식 1 ) {... if ( 조건식 2 ) c o n tin u e ;... d o {... if ( 조건식 2 ) c o n tin u e ;... w h ile ( 조건식 1 ); fo r ( 초기값 ; 조건식 1 ; 증감식 ){... if ( 조건식 2 ) c o n tin u e ;...
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < % @ p a g e im p o rt = " ja v a.u til.r a n d o m " % > < h tm l> < h e a d > < title > c o n tin u e 예 < / title > < / h e a d > < b o d y > < % R a n d o m ra n d o m = n e w R a n d o m (); fo r (in t i = 1 ; i < = 1 0 ; i+ + ) { in t n u m b e r = ra n d o m.n e x tin t(1 0 ) + 1 ; if (n u m b e r = = 5 ) c o n tin u e ; o u t.p rin tln (i + " 번째값 : " + n u m b e r + " < b r/> " ); % > < / b o d y > < / h tm l>
S trin g s tr = " js p b o o k 웹어플리케이션 " ; / / 문자열리터럴할당 S trin g s tr = n e w S trin g (" js p b o o k 웹어플리케이션 " ); / / 문자열객체할당 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > S trin g 동일성판단예제 < / title > < / h e a d > < b o d y > < % S trin g s tr1 = " js p b o o k 웹어플리케이션 " ; S trin g s tr2 = " js p b o o k 웹어플리케이션 " ; S trin g s tr3 = n e w S trin g (" js p b o o k 웹어플리케이션 " ); % > s tr1 = = s tr2 : < % = s tr1 = = s tr2 % > < b r/> s tr1 = = s tr3 : < % = s tr1 = = s tr3 % > < b r/> s tr2 = = s tr3 : < % = s tr2 = = s tr3 % > < b r/> s tr1.e q u a ls (s tr2 ): < % = s tr1.e q u a ls (s tr2 ) % > < b r/> s tr1.e q u a ls (s tr3 ): < % = s tr1.e q u a ls (s tr3 ) % > < b r/> s tr2.e q u a ls (s tr3 ): < % = s tr2.e q u a ls (s tr3 ) % > < b r/> < / b o d y > < / h tm l>
각문자 H e l l o, W o r l d 인덱스 0 1 2 3 4 5 6 7 8 9 1 0 1 1 각문자안녕 J S P! 인덱스 0 1 2 3 4 5 6
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < h tm l> < h e a d > < title > S trin g 메소드예제 < / title > < / h e a d > < b o d y > < % S trin g s tr1 = " fris t s trin g " ; S trin g s tr2 = " s e c o n d s trin g " ; S trin g s tr3 = " JS P 프로그래밍!" ; % > s tr1 : < % = s tr1 % > < b r/> s tr2 : < % = s tr2 % > < b r/> s tr3 : < % = s tr3 % > < b r/> < h r/> s tr1.le n g th (): < % = s tr1.le n g th () % > < b r/> s tr2.le n g th (): < % = s tr2.le n g th () % > < b r/> s tr3.le n g th (): < % = s tr3.le n g th () % > < b r/> < h r/> s tr1.c h a ra t(4 ): < % = s tr1.c h a ra t(4 ) % > < b r/> s tr1.in d e x O f(" in g " ): < % = s tr1.in d e x O f(" in g " ) % > < b r/> s tr1.in d e x O f(" s t", 4 ): < % = s tr1.in d e x O f(" s t", 4 ) % > < b r/ > s tr2.in d e x O f('s '): < % = s tr2.in d e x O f('s ') % > < b r/> s tr2.in d e x O f('s ', 4 ): < % = s tr2.in d e x O f('s ', 4 ) % > < b r/> s tr3.in d e x O f(" 프로그래밍 " ): < % = s tr3.in d e x O f(" 프로그래밍 " ) % > < b r/> < h r/> s tr1.s u b s trin g (6 ): < % = s tr1.s u b s trin g (6 ) % > < b r/> s tr2.s u b s trin g (4, 9 ): < % = s tr2.s u b s trin g (4, 9 ) % > < b r/> s tr3.s u b s trin g (4 ): < % = s tr3.s u b s trin g (4 ) % > < b r/> < h r> s tr1.e q u a ls (s tr2 ): < % = s tr1.e q u a ls (s tr2 ) % > < b r/> s tr1.c o m p a re T o (s tr2 ): < % = s tr1.c o m p a re T o (s tr2 ) % > < b r/> < / b o d y > < / h tm l> 각문자 f i r s t s t r i n g 인덱스 0 1 2 3 4 5 6 7 8 9 1 0 1 1
각문자 s e c o n d s t r i n g 인덱스 0 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 각문자 J S P 프로그래밍! 인덱스 0 1 2 3 4 5 6 7 8 9
S trin g T o k e n iz e r s t = n e w S trin g T o k e n iz e r(" 2 0 0 8-9 - 6 / 토요일 ", " - / " );
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 < % @ p a g e c o n te n tt y p e = " te x t/ h tm l;c h a rs e t= u tf- 8 " % > < % @ p a g e im p o rt= " ja v a.u til.s trin g T o k e n iz e r" % > < h tm l> < h e a d > < title > S trin g T o k e n iz e r 메소드예제 < / title > < / h e a d > < b o d y > < % S trin g s tr = " 2 0 0 8 / 0 9 / 0 6 " ; S trin g T o k e n iz e r s t = n e w S trin g T o k e n iz e r(s tr, " / " ); % > s t.c o u n tt o k e n s () = < % = s t.c o u n tt o k e n s () % > < b r/> < % w h ile (s t.h a s M o re T o k e n s ()){ % > s t.n e x tt o k e n s () = < % = s t.n e x tt o k e n () % > < b r/> < % % > < / b o d y > < / h tm l>