輸入4個數字,並推算出第5個數字
輸入:
2
1 2 3 4
1 2 4 8
輸出:
1 2 3 4 5
1 2 4 8 16
import java.util.Scanner;
import java.io.*;
public class Test{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int [][] b;
b = new int [a][5];
for(int i = 0; i < a; i++){
for(int j = 0; j < 4; j++){
b[i][j] = sc.nextInt();
}
if( b[i][3]-b[i][2] == b[i][1]-b[i][0] ){
b[i][4] = b[i][3] + ( b[i][3]-b[i][2] );
}
else{
b[i][4] = b[i][3] * (b[i][3] / b[i][2]);
}
for(int x = 0; x < 5; x++){
System.out.print(b[i][x] + " ");
}
System.out.println();
}
}
}
沒有留言:
張貼留言