✅ 문제

 

✅ 코드

class Solution {
    public String solution(String[] arr) {
        String answer = "";
        
        for (int i =0; i<arr.length;i++) {
        	answer+=arr[i];
        }
        
        return answer;
    }
}

✅ 문제

 

 

✅ 코드

 

class Solution {
    public int solution(int num, int n) {
        int answer = 0;
        
        if((num % n==0)){
            answer= 1;
        } else{
            answer=0;
        }
            
        
        return answer;
    }
}

 

✅ 문제

✅ 코드

 

class Solution {
    public String solution(String str1, String str2) {
       String answer = "";

		for(int i=0;i<str1.length();i++) {
			answer=answer+str1.charAt(i)+str2.charAt(i);
		}
		
		return answer;
    }
}

https://beastit.tistory.com/36

 

[Byte Order]Big Endian(빅 엔디안) & Little Endian(리틀 엔디안)

🟩 Byte Order (바이트 저장 순서) 컴퓨터는 데이터를 메모리에 저장할 때 바이트(byte) 단위로 나눠서 저장합니다. 하지만 컴퓨터가 저장하는 데이터는 32비트(4바이트) 또는 64비트(8바이트)로 구성

beastit.tistory.com

 

글 시작 전에 위에 글을 먼저 보면 왜? 하는지 알 수 있다.

 

✅ 비트맵 이미지로 필요한 데이터 추출하기

 

맨 위부터 보면 Signature(2byte), File Size (4byte)...... 각 층마다 4byt의 해당 정보들을 가지고 있다.

 

우리가 필요한 정보는 Image Width, Height의 데이터를 추출하고 싶다.

 

19~22바이트, 23~26바이트에 접근하면 추출 할 수 있음

 

" 1314x736 "

 

 

 

 

import java.io.FileInputStream;
import java.io.IOException;

public class homework {

	public static void main(String[] args) throws IOException {
		// 4바이트 데이터 읽기
		int n1 , n2, n3, n4 ;
		int n5 , n6, n7 , n8 ;

		// Image Width & Height
		{
			FileInputStream fis = new FileInputStream("res/pic1.bmp");

			//필요없는 데이터 건너뛰
			//Signature
			fis.read();
			fis.read();

			//File Size
			fis.read();
			fis.read();
			fis.read();
			fis.read();

			//Reserved 1,2
			fis.read();
			fis.read();
			fis.read();
			fis.read();

			//File Offset to PixelArray
			fis.read();
			fis.read();
			fis.read();
			fis.read();
			
			//DIB Header Size
			fis.read();
			fis.read();
			fis.read();
			fis.read();
			
			//Image Width
			n1=fis.read();
			n2=fis.read();
			n3=fis.read();
			n4=fis.read();
			
			//Image Height
			n5=fis.read();
			n6=fis.read();
			n7=fis.read();
			n8=fis.read();
			
			
			
			int width = n1 << 0 | n2 << 8 | n3 << 16 | n4 << 24;
			int height = n5 << 0 | n6 << 8 | n7 << 16 | n8 << 24;
			
			System.out.printf("Width : %d, Height : %d\n",width,height );

		}

	}

}

 

✅ 결과

 


 

비트맵 파일을 바이너리 에디터로 보면 Image Width (19~22바이트), Image Height (23~26바이트)

 

🔸 Image Width : 034 005 000 000

🔸 Image Height : 224 002 000 000

 

인텔 CPU 계열에서는 낮은 주소에 데이터의 낮은 바이트부터 저장하는 방식"리틀 엔디안(Little Endian)" 방식으로 저장한다.

우리는 이것을 낮은 주소에 데이터의 높은 바이트부터 저장하는 방식"빅 엔디안(Big Endian)" 방식으로 비트연산자를 써서 저장할 것이다. 

 

int width = n1 << 0 | n2 << 8 | n3 << 16 | n4 << 24;
int height = n5 << 0 | n6 << 8 | n7 << 16 | n8 << 24;

 

  • n1 :                                                                 0010 0010 (34)
  • n2 :                                            0000 0101 0000 0000 (5)
  • n3 :                      0000 0000 0000 0000 0000 0000 (0)
  • n4 : 0000 0000 0000 0000 0000 0000 0000 0000 (0)  

  width : 0000 0000 0000 0000 0000 0101 0010 0010  

 

or( | ) 연산자를 사용하면 위와 같이 비트 이동이 이루어 지면서 저장 값이 바뀌게 된다.

 

  • n5 :                                                                  1110 0000 (224)
  • n6 :                                            0000 0010 0000 0000 (5)
  • n7 :                       0000 0000 0000 0000 0000 0000 (0)
  • n8 :  0000 0000 0000 0000 0000 0000 0000 0000 (0)  

  width : 0000 0000 0000 0000 0000 0010  1110  0000 

public class program {

	public static void main(String[] args) {

		String name1 = "아이유";// 실행환경이 입힌 갑옷
//		String name2 = "아이유";
		String name2 = new String("아이유");// 내가 입힌 갑옷
		// ==이라는 기호가 값이 같은지? 박스가 같은지? 비교해보자.
		// 결과는 false가 나온다. 참조하는 객체가 달라서 이럼.

		System.out.println(name1 == name2);// 같은 객체를 참조하고 있는지를 비교 false
		System.out.println(name1.equals(name2));// 객체의 값이 같은지를 비교 true
		System.out.println(name1 == "아이유");// 결과는 true name1박스에서 만든 박스로 비교하는것. true

		System.out.println("----------------------------------------------");

		// 파일명에서 확장자를 제외한 파일명만 출력하시오.
		// =위의 팡리명에서 점(.)이 있는 곳까지의 문자열을 출력하시오.(단 점(.) 제외)
		String fileName = "photo.jpg";
		System.out.println(fileName.length());// 문자열의 길이를 알 수 있다. 결과 값 : 9
		System.out.println(fileName.indexOf("."));// "." 의 위치를 알 수 있다. 5번째에 위치하고 있음.
		System.out.println(fileName.substring(0, 3));// 0~3까지의 문자만 출력한다. pho가 나온다.
		System.out.println(fileName.substring(0, 5));// 0~5까지의 문자만 출력한다. photo가 나온다.

		String p = fileName.substring(0, 5);
		String w = fileName.substring(6, 9);
		System.out.printf("\n%s"+"%s\n",p,w);
		
		
		int index = fileName.indexOf(".");// 점(.)이 위치한값을 구해서 index에 저장한다.
		String name = fileName.substring(0,index);//
		System.out.println(name);//끝나는 부분을 index으로 설정.
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		int x = 3;
		Integer 정수갑옷 = Integer.valueOf(x);// new Integer(x); Boxing
		int x1 = 정수갑옷.intValue();// Unboxing
		

		String y = "hello";// 태생이 갑옷을 입고있는 문자열!

		double d1 = 3.9;
		Double 더블갑옷 = Double.valueOf(d1);// new Double(d1);
		double d2 = 더블갑옷.doubleValue();// Unboxing

		// ---정수를 문자열로 변환 & 문자열을 더블로 변환.
		int n1 = 10;
		String s1 = String.valueOf(n1);

		String s2 = "30.2";
		double n2 = Double.parseDouble(s2);
	}

문제

사전 구상

 

  • my_string을 s까지 추출 후 overwrite_string 을 합친다.
  • "s+overwrite_string.length()" 길이만큼 my_string에서 추출 후 합쳐줌.

 

✅ 결과

 

package lv_0;

class overwrite_String {
	public String solution(String my_string, String overwrite_string, int s) {

		String myStr = my_string;
		String overStr = overwrite_string;

		// 예시) "He11oWor1d" / "lloWorl" / s =2
		// myStr.substring(0, s) -> "He"
		// overStr = "lloWorl"
		// my_string.substring(overStr.length() + s) -> 7+2 = 9번째 문자 추 
		//위 3개를 합쳐주면 변경된 문자열로 출
		//
		return myStr.substring(0, s) + overStr + my_string.substring(overStr.length() + s);

	}

}

 


 

+ Recent posts