-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSum of two numbers
43 lines (41 loc) · 1.39 KB
/
Sum of two numbers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package NestedLoops.Lab;
import java.util.Scanner;
public class sumOfTwoNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int i = Integer.parseInt(input.nextLine()), j = Integer.parseInt(input.nextLine()), k = Integer.parseInt(input.nextLine());
int counter = 0, c = 0, d = 0;
if (i < j){
for (int a = i; a <= j; a++){
for (int b = i; b <= j; b++){
counter ++;
c = a;
d = b;
if (a + b == k){
System.out.printf("Combination N:%d (%d + %d = %d)", counter, a, b, k);
a = j;
b = j;
break;
}
}
}
} else {
for (int a = j; a <= i; a++){
for (int b = j; b <= i; b++){
c = a;
d = b;
counter ++;
if (a + b == k){
System.out.printf("Combination N:%d (%d + %d = %d)", counter, a, b, k);
a = i;
b = i;
break;
}
}
}
}
if (c + d != k){
System.out.printf("%d combinations - neither equals %d", counter, k);
}
}
}