2016-12-12 4 views
-1

이 프로그램의 출력은 다음과 같습니다두 개의 연결된 문자열의 바이트 값을 가져 오는 방법 ...?

[[email protected][[email protected] 
[[email protected] 

필요한 출력은 다음과 같습니다

[[email protected][[email protected] 
[[email protected][[email protected] 

이 도와주세요 ... 당신의 결과에

import java.util.Scanner; 
import java.io.InputStreamReader; 

public class testme { 
    public static void main(String[] args) { 
     Scanner in = new Scanner(new InputStreamReader(System.in)); 
     String s = "hello"; 
     String sb = "hi"; 
     String sc = s.concat(sb); 
     byte[] a, b; 
     a = s.getBytes(); 
     b = sb.getBytes(); 
     byte[] c = new byte[a.length + b.length]; 
     System.arraycopy(a, 0, c, 0, a.length); 
     System.arraycopy(b, 0, c, a.length, b.length); 
     System.out.println(a + "" + b + "\n" + c); 
    } 
} 
+0

? 개미

import java.util.Arrays; public class Solution { public static void main(String[] args) { String s = "hello"; String sb = "hi"; byte[] a, b; a = s.getBytes(); b = sb.getBytes(); byte[] c = new byte[a.length + b.length]; System.arraycopy(a, 0, c, 0, a.length); System.arraycopy(b, 0, c, a.length, b.length); System.out.println(" Arrays.toString(a)= "+Arrays.toString(a)); System.out.println(" Arrays.toString(b)= "+Arrays.toString(b)); System.out.println(" Arrays.toString(c)= "+Arrays.toString(c)); } } 

출력은, Arrays.toString 방법을 인쇄 해보십시오 값이 연결됩니다 알고 여부합니다 –

+0

전체 프로그램의 목적은 무엇입니까? – Kayaman

+0

그건 말이 안됩니다. 세 개의 배열 (정확히 말해서 그 배열의 toString) 만 출력하면 "[B"는 네 번 출력되지 않습니다. 또한 String 표현은 결정적이지 않은 배열의 objectId에 따라 다릅니다. 배열 내용을 인쇄하고 싶습니다. toString ... –

답변

0

[[email protected], the [B means byte[] and 171ccb0 is the memory address of a variable used, separated by an @. 

Similarly, in [[email protected] , 35378d is the memory address of b variable created, and 

in [[email protected], 1d23632 is the memory address of c variable created. 

경우 너 w

Arrays.toString(a)= [104, 101, 108, 108, 111] 
Arrays.toString(b)= [104, 105] 
Arrays.toString(c)= [104, 101, 108, 108, 111, 104, 105] 

참조 : How to convert Java String into byte[]? 당신의 예에서 스캐너의 목적은 무엇