View Code of Problem 10

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int d = 0;
		int x;
		int a[] = new int[4];
		for (int i = 0; i < 4; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 1; i <4; i++ ) {
			if (a[i] == a[i - 1]) {
				a[i] *= 2;
				d++;
				a[i - 1] = 0;
			}
		}
		for (int i = 1; i <4; i++) {
			if (a[i] == 0) {
				x = a[i];
				a[i] = a[i - 1];
				a[i - 1] = x;
			}
		}
		for (int i = 0; i < 4; i++) {
			System.out.print(a[i]+" ");
		}
	}

}

Double click to view unformatted code.


Back to problem 10