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 firstNum = Integer.parseInt(scanner.nextLine()),
- secondNum = Integer.parseInt(scanner.nextLine()),
- magicNum = Integer.parseInt(scanner.nextLine()),
- combinations = 0;
- boolean isFound = false;
- for (int i = firstNum; i <= secondNum; i++) {
- for (int j = firstNum; j <= secondNum; j++) {
- combinations++;
- if (i + j == magicNum) {
- System.out.printf("Combination N:%d (%d + %d = %d)\n", combinations, i, j, magicNum);
- isFound = true;
- break;
- }
- }
- if (isFound) {
- break;
- }
- }
- if (isFound == false) {
- System.out.println(combinations + " combinations - neither equals " + magicNum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement