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