티스토리 뷰

https://www.acmicpc.net/problem/10093

 

10093번: 숫자

두 양의 정수가 주어졌을 때, 두 수 사이에 있는 정수를 모두 출력하는 프로그램을 작성하시오.

www.acmicpc.net

 

문제를 제대로 읽고 맞는 자료형을 써야하는 문제였다. ( int -> long )

 

public class Q10093 {
	static Scanner sc;
	static long left;
	static long right;
	
	public static void main(String args[]) {
		solve();
	}
	
	public static void solve() {
		init();
		answer();
	}
	
	public static void init() {
		sc = new Scanner(System.in);
		left = sc.nextLong();
		right = sc.nextLong();
		if(left > right) {
			long temp = right;
			right = left;
			left = temp;
		}
	}
	
	public static void answer() {
		if(right == left) {
			System.out.println(0);
			return;
		}
		
		long twoNumberInCount = right - left - 1;
		System.out.println(twoNumberInCount);
		
		for(long num = left + 1; num < right; num++) {
			System.out.print(num + " ");
		}
	}
	
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함