๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[Java] ์ด์ฐจ์›๋ฐฐ์—ด ๊ธธ์ด ๊ตฌํ•˜๊ธฐ

int[][] arr1 = { {1,2,3}, {2,3,4} } arr1.length --> 2 ( arr1์˜ ๊ธธ์ด { { v }, { v } } ) // v๊ฐ€ ๊ฐœ์ˆ˜ ์ฒดํฌ arr1[0].length --> 3 ( arr1[0]์˜ ๊ธธ์ด { {v,v,v}, {_,_,_} } ) arr1.length ๋Š” arr1์˜ ๊ธธ์ด arr1[0].length ๋Š” arr1[0]์˜ ๊ธธ์ด ๊ฐ„๋‹จํ•˜์ง€๋งŒ ํ—ท๊ฐˆ๋ฆด ์ˆ˜ ์žˆ๋‹ค.. ๋ฐ˜๋ณต๋ฌธ์€ ์ด๋Ÿฐ์‹์œผ๋กœ.. for(int i=0; i

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[Java] ์ •๊ทœํ‘œํ˜„์‹ ์ •๋ฆฌ

์ •๊ทœํ‘œํ˜„์‹์„ ์•ˆ๊นŒ๋จน๊ธฐ์œ„ํ•ด์„œ ์ •๋ฆฌํ•ด๋ณธ๋‹ค. ์ •๊ทœํ‘œํ˜„์‹์„ ์•Œ๋ฉด ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง€๊ณ  , ์—„์ฒญ๋‚œ ์‹œ๊ฐ„์„ ๋‹จ์ถ•์‹œํ‚ฌ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๊ณต๋ถ€ํ•ด๋ณด์ž. ์˜ˆ๋ฅผ ๋“ค์–ด, replaceAll์œผ๋กœ ๋“ค์–ด๋ดค๋‹ค. []์€ ๋ฌธ์ž,์ˆซ์ž์˜ ์ง‘ํ•ฉ์„ ๋‚˜ํƒ€๋‚ด๊ณ , ๋ฌธ์ž,์ˆซ์ž ์‚ฌ์ด์—๋Š” - ๋กœ ๋ฒ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋งŒ์•ฝ [] ์•ˆ์— ^๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด ์ œ์™ธํ•œ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค. String pn = "a123b456c789"; String str = pn.replaceAll("[0-9]", ""); // 0๋ถ€ํ„ฐ9๊นŒ์ง€ ์ˆซ์ž๋ฅผ ๊ณต๋ฐฑ("")์œผ๋กœ ํ‘œํ˜„ -> abc String str = pn.replaceAll("[^0-9]", ""); // 0๋ถ€ํ„ฐ9๊นŒ์ง€๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€๋ฅผ ๊ณต๋ฐฑ("")์œผ๋กœ ํ‘œํ˜„ -> 123456789 [์ž์ฃผ ์“ฐ์ด๋Š” ํŒจํ„ด] ์ˆซ์ž๋งŒ ^[0-9]*$ ์˜๋ฌธ์ž๋งŒ ^[a-zA-Z..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[Java] equals() , equalsIgnoreCase() ์ฐจ์ด์ 

๋งŒ์•ฝ, scanner๋กœ input์„ ๋ฐ›๋‹ค๊ฐ€ "q"๋ฅผ ์ž…๋ ฅ๋ฐ›์œผ๋ฉด ์ข…๋ฃŒ๋˜๊ฒŒ ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์ฒ˜๋Ÿผ ์งœ์•ผํ•œ๋‹ค. Scanner sc = new Scanner(System.in); String input = sc.nextLine(); if( input.equals("q") || input.equals("Q") ){ break; } ์ด๋ ‡๊ฒŒ q , Q ๋‘๊ฐ€์ง€ ์ƒํ™ฉ์„ ์ƒ๊ฐํ•ด์ค˜์•ผํ•œ๋‹ค. ๊ทผ๋ฐ equalsIgnoreCase๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, q์™€Q๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€์•Š๋Š”๋‹ค. Scanner sc = new Scanner(System.in); String input = sc.nextLine(); if( input.equalsIgnoreCase("q") ){ break; } ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด, ์ข€ ๋” ์‹คํ–‰์†๋„๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค. ..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[Java] String.replace ์™€ replaceAll ์ฐจ์ด์ 

import java.lang.String; String replace(CharSequnce target, CharSequence replacement) String replaceAll(String regex, String replacement) replace String str = "abcdeababaaababababcddeee"; str.replace("abc", "ํ—ฟ"); --------------------------------------------------- str -> ํ—ฟdeababaaabababํ—ฟddeee replaceAll String str = "abcdeababaaababababcddeee"; str.replaceAll("[abc]", "ํ—ฟ"); ---------------------..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[Java] ์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ• - ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜, ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜

์ตœ๋Œ€๊ณต์•ฝ์ˆ˜, ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ๊ตฌํ•˜๊ธฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜ 1. ๋ฐ˜๋ณต๋ฌธ ๋Œ๋ฆฌ๊ธฐ int a = 12, b = 3; int gcd = 0 , lcm = 0; int r = 1; //์ตœ๋Œ€๊ณต์•ฝ์ˆ˜ ๊ตฌํ•˜๋Š” ๋ฉ”์†Œ๋“œ int gcd( int a , int b ){ while( r > 0 ){ r = a % b; a = b; b = r; } return a; } gcd = gcd(a , b); lcm = (a * b) / gcd; 2. ์žฌ๊ท€ ํ•จ์ˆ˜ ์‚ฌ์šฉ int a = 12, b = 3; int gcd = 0, lcm = 0; //๋ฐ˜๋ณต๋ฌธ์ฒ˜๋Ÿผ ๋„๋Š” ์žฌ๊ท€ํ•จ์ˆ˜. int makeGCD( int a, int b){ if( b == 0){ return a; } else { return gcd( b, a%b ); } } gcd = makeGCD(a , b)..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[Java] ์‚ผํ•ญ ์—ฐ์‚ฐ์ž

if ๋ฌธ ๋Œ€์‹  ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์‚ผํ•ญ ์—ฐ์‚ฐ์ž. public class Test1{ public static void main(String[] args) { /*======================= * 3ํ•ญ ์—ฐ์‚ฐ * ====================== */ String s = "Ab^^abc"; String answer = ""; int idx = -1; String[] arr = s.split(""); for(String ss : arr) { idx = ss.contains("^") ? -1 : idx + 1; answer += (idx % 2 == 0) ? ss.toUpperCase() : ss.toLowerCase(); } System.out.println(answer); /*==========..

iseunghan
'๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (7 Page)