2진표현~ ★☆무엇이 무엇이 틀렸을까요 ★☆★☆알아맞춰 보세요~!

portishead Reply 9 years 7 weeks ago
import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner input = new Scanner(System.in); int N = input.nextInt(); short[] array = new short[N]; for(int i =0; i<N; i++){ array[i] = input.nextShort(); } for(int i=0;i<N;i++){ int[] bitArray = new int[16]; if(array[i]>=0){ for(int j=0;j<bitArray.length;j++){ bitArray[bitArray.length-j-1] = array[i]%2; array[i]/=2; System.out.print(bitArray[j]); } } else if(array[i]<0){ int minus = (int)array[i]; minus *= -1; minus = (int)(Math.pow(2, 16))-1 - minus +1; for(int j=15;j>=0;j--){ bitArray[j] = minus%2; minus/=2; } for (int j=0;j<16;j++) { System.out.print(bitArray[j]); } } if(i!=N-1) System.out.print("\n"); } } } 샘플은 모두 잘 나오는데 ~@!! 왜~~ 롱앤써가!!! 뙇!!!!!!!!!!!