Advertisement
veronikaaa86

Two Numbers

Nov 2nd, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package Exam;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Demo {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int m = Integer.parseInt(scanner.nextLine());
  10.         int n = Integer.parseInt(scanner.nextLine());
  11.         int magic = Integer.parseInt(scanner.nextLine());
  12.  
  13.         String comb = "";
  14.         int counter = 0;
  15.         int sum = 0;
  16.         for (int i = m; i <= n; i++) {
  17.             for (int j = m; j <= n; j++) {
  18.                 counter++;
  19.                 sum = i + j;
  20.                 if (i+j==magic){
  21.                    comb = i + "" + j + "";
  22.                     System.out.printf("Combination N:%d ", counter);
  23.                     System.out.printf("(%d + %d = %d)", i, j, magic);
  24.                    break;
  25.                 }
  26.             }
  27.             if (sum==magic) {
  28.                 break;
  29.             }
  30.         }
  31.         if ("".equals(comb)) {
  32.             System.out.printf("%d combinations - neither equals %d", counter, magic);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement