[Day10] Java 10 [8/22]

 

1.  String ํด๋ž˜์Šค ํ•จ์ˆ˜(๋ฉ”์„œ๋“œ) 

charAt(index)
equals()
split(regex)
matches(regex)
substring()
trim()
valueOf()
format()
join()

2.  10์ง„์ˆ˜ 2์ง„์ˆ˜ ์ „ํ™˜

// [๋ฌธ์ œ] 10์ง„์ˆ˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„์„œ
		//   2๋ฐ”์ดํŠธ 2์ง„์ˆ˜ํ˜•ํƒœ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”.
		// ์˜ˆ) 10
		//     0000 0000    0000 1010 
		Scanner scanner = new Scanner(System.in);
		System.out.print("> 10์ง„์ˆ˜ ์ •์ˆ˜ ์ž…๋ ฅ ? ");
		int n = scanner.nextInt();
		 
		int [] binaryArray = new int[16];

		int index = binaryArray.length - 1;
		
		// 4:10 ํ’€์ด ์‹œ์ž‘
		// n = 10
		int share = n, rest ;
		
		/*
		share = share /2;  // 5
		rest = share % 2;    // 0
		binaryArray[ index ] = rest;
		index--;
		
		share = share /2;  //      2
		rest = share % 2;    //        1
		binaryArray[ index ] = rest;
		index--;
		
		share = share /2;  //      1
		rest = share % 2;    //   0
		binaryArray[ index ] = rest;
		index--;
		
		:
		:
		*/
		// ์ค‘๋‹จ์ (break point)               F11  ๋””๋ฒ„๊น…~
		while(  share != 0 ) {   
			rest = share % 2;    
			share = share /2;   
			binaryArray[ index-- ] = rest;   
		}
		
		// int [] ๋ฐฐ์—ด์€ ์ดˆ๊ธฐํ™” ํ•˜์ง€ ์•Š์œผ๋ฉด int์˜ ๊ธฐ๋ณธ๊ฐ’์ธ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ๋˜์–ด์ ธ ์žˆ๋‹ค...( ์•”๊ธฐ )
		// [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
		System.out.println(   Arrays.toString(  binaryArray )  );
		// 00000000000010
		String result =  Arrays.toString(  binaryArray ) ;
		result =  result.replaceAll(",\\s", "");
		System.out.println( result.substring(1, result.length()-1) );
String binaryN = Integer.toBinaryString( n )

 

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ