View Code of Problem 10

import java.util.*;				
						
public class QUESTIONS {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		for (int k = in.nextInt(); k > 0; k--) {
		
		int x;
		int a[] = new int[4];

		for (int i = 0; i < 4; i++) {
			a[i] = in.nextInt();
		}
		for (int j = 0; j < 4; j++) {
			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 = 3; i > 0; i--) {
			if (a[i] == a[i - 1]) {
				a[i] *= 2;
			
				a[i - 1] = 0;
			}
		}
		for (int j = 0; j < 4; j++) {
			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<a.length;i++){
	if(i!=3)
	System.out.print(a[i]+" ");
	else
	System.out.println(a[i]);
}
	}
	}
 
}
/*
Main.java:3: error: class QUESTIONS is public, should be declared in a file named QUESTIONS.java
public class QUESTIONS {
       ^
1 error
*/

Double click to view unformatted code.


Back to problem 10