JAVA/JAVA Algorithm, Datastruct

[Algorithm] JAVA 코드업 기초 100제 (기초-비트시프트연산) 1047 ~ 1048

큐범 2022. 8. 30. 19:52

1047 : [기초-비트시프트연산] 정수 1개 입력받아 2배 곱해 출력하기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		
		System.out.printf("%d", i<<1);
	}

1048 : [기초-비트시프트연산] 한 번에 2의 거듭제곱 배로 출력하기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		
		System.out.printf("%d",
				Integer.parseInt(s.substring(s.indexOf(0)+1, s.indexOf(" ")))
				<<
				Integer.parseInt(s.substring(s.indexOf(" ")+1)));
	}