Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class NumberFun {
- private static boolean addition (int a, int b, int ans) {
- int temp;
- if (a > b) {
- temp = a;
- a = b;
- b = temp;
- }
- while (a < b) {
- if (a + b == ans) {
- return true;
- }
- else {
- a = a+b;
- }
- }
- return false;
- }
- private static boolean subtraction (int a, int b, int ans) {
- int temp;
- if (a < b) {
- temp = a;
- a = b;
- b = temp;
- }
- while (a > b) {
- if (a - b == ans) {
- return true;
- }
- else {
- a = a - b;
- }
- }
- return false;
- }
- private static boolean multiplication(int a, int b, int ans) {
- int temp;
- if (a > b) {
- temp = a;
- a = b;
- b = temp;
- }
- while (a < b) {
- if (a * b == ans) {
- return true;
- }
- else {
- a = a*b;
- }
- }
- return false;
- }
- private static boolean division (int a, int b, int ans) {
- int temp;
- if (a < b) {
- temp = a;
- a = b;
- b = temp;
- }
- while (a > b) {
- if (a / b == ans) {
- return true;
- }
- else {
- a = a/b;
- }
- }
- return false;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int a; int b; int c;
- int range = sc.nextInt();
- for (int i = 0; i < range; i++) {
- a = sc.nextInt();
- b = sc.nextInt();
- c = sc.nextInt();
- if (addition(a,b,c) || subtraction(a,b,c) || division(a,b,c) || multiplication(a,b,c)) {
- System.out.println("Possible");
- }
- else {
- System.out.println("Impossible");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement