skipter

Two Number Sum - Java Basics Exam 19 March 2017

May 3rd, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner input = new Scanner(System.in);
  10.  
  11.         int startInterval = Integer.parseInt(input.nextLine());
  12.         int endInterval = Integer.parseInt(input.nextLine());
  13.         int magicNumber = Integer.parseInt(input.nextLine());
  14.  
  15.         int combination = 0;
  16.  
  17.         for (int i = startInterval; i >= endInterval ; i--) {
  18.             for (int j = startInterval; j >= endInterval ; j--) {
  19.                 combination++;
  20.                 if (i + j == magicNumber) {
  21.                     System.out.printf("Combination N:%d (%d + %d = %d)", combination, i, j, magicNumber);
  22.                     return;
  23.                 }
  24.             }
  25.         }
  26.         System.out.printf("%d combinations - neither equals %d", combination, magicNumber);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment