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