포스코 2023-10-24

Giho Kim·2023년 10월 24일
package hello;
import java.util.Scanner;

public class hello {
	public static void main(String args[]) {
		System.out.print("아하");
		System.out.println("아하");
		System.out.printf("오호 %1.2f", 1.24);
		System.out.printf("%15.10s", "hello world");
		
		Scanner scanner = new Scanner(System.in);
		// String input = scanner.next();
		String input = scanner.nextLine();
		Integer.parseInt("3");
		}

}

%1.2f --> 한자리 + 소수점

%10s --> 최소한 나와야되는 자리수 --> 그냥 숫자는 앞에 공백, -면 뒤에 공백

package hello;
import java.util.Scanner;

public class hello {
	public static void main(String args[]) {
		int i = 127;
		
		String binaryString = Integer.toBinaryString(i);
		String octalString = Integer.toOctalString(i);
		String hexString = Integer.toHexString(i);
		
		System.out.println(binaryString);
		System.out.println(octalString);
		System.out.println(hexString);
		}

}
package hello;
import java.util.Scanner;

public class main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		int n = scanner.nextInt();
		
		int check = 0x80000000;
		String binaryString = Integer.toBinaryString(num);
		System.out.println(binaryString);
		
		for (int i = 0; i < n; i++) {
			if (num >= 0) {
				// & 1이랑 마지막 비트 같으면 --> 1
				
				if ((num & 1) == 0) {
					num = num >> 1;
				}
				// & 1이랑 마지막 비트 다르면 --> 0
				else {
					num = num >> 1;
					num = (num | check); // 0x80000000 -> 0x - 16진법 1000 / 0000 / ...
											  //                      8  / 0    / ...
					// 010000
					// 100000
					// 110000
					
					
				}
			}
			
			else {
				
				// & 1이랑 마지막 비트 같으면 --> 1
				if ((num & 1) == 1) {
					num = num >> 1;
				}
				
				else {
					num = num >> 1;
					num = (num & 0x7FFFFFFF);   // 1011 001...0000
												// 1101 1001...000|0
												// 0111 1111...1111
												// 0101 1001...0000
				}
			}
		}
		for (int j = 0; j < 32; j++) {
			if ((num & check) != 0) {
				System.out.print("1");
			}
			else {
				System.out.print("0");
			}
			check = check >>> 1;
		}
	}

}

비트 연산자써서 뭐 비트 뒤에꺼 앞으로 가져다주는거 해봄

package reversesqueeze;
import java.util.Scanner;

public class revsqueeze {
	public static void main(String[] args) {
		System.out.println("문자열\n문자");
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		char c = sc.next().charAt(0);
		
		
		String result = revsqueeze(s,c);
		String result2 = revsqueeze2(s,c);
		System.out.println(result);
		System.out.println(result2);
	}
	
	public static final String revsqueeze(String s, char c) {
		String temp = "";
		char[] arrayS = s.toCharArray();
		
		for (int i = 0; i < s.length(); i++) {
			if (arrayS[i] != c) {
				temp += arrayS[i];
			}
		}
		
		StringBuffer sb = new StringBuffer(temp);
		String return_value = sb.reverse().toString();
		return return_value;
	}
	
	public static final String revsqueeze2(String s, char c) {
		String temp = "";
		char[] arrayS = s.toCharArray();
		
		for (char i : arrayS) {
			if (i != c) {
				temp += i;
			}
		}
		
		StringBuffer sb = new StringBuffer(temp);
		String return_value = sb.reverse().toString();
		return return_value;
	}
}

배열 바꾸는거 했는데 array 만들때 char [] 선언해줘야 되는게 ㄹㅇ 귀찮다. 파이썬으로 돌아갈래

profile
취준돌이 개발자 김기호

0개의 댓글