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