Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P06_TwoNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int first = Integer.parseInt(scanner.nextLine());
- int last = Integer.parseInt(scanner.nextLine());
- int magic = Integer.parseInt(scanner.nextLine());
- int sum = 0;
- int counter = 0;
- int one = 0;
- int two = 0;
- for (int i = first; i >= last; i--) {
- for (int j = first; j >= last; j--) {
- counter++;
- if ((i + j) == magic) {
- sum = i + j;
- one = i;
- two = j;
- break;
- }
- }
- if (sum == magic) {
- break;
- }
- }
- if (sum==magic) {
- System.out.printf("Combination N:%d (%d + %d = %d)", counter, one, two, magic);
- } else {
- System.out.printf("%d combinations - neither equals %d", counter, magic);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement