aneliabogeva

SumOfTwoNumbers

Nov 26th, 2020
413
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class SumOfTwoNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         Integer number1 = scanner.nextInt();
  7.         Integer number2 = scanner.nextInt();
  8.         Integer magicNumber = scanner.nextInt();
  9.         Integer counter = 0;
  10.         Integer negativeCounter = 0;
  11.         Integer n1 = 0;
  12.         Integer n2 = 0;
  13.         Boolean checkPoint = false;
  14.  
  15.         for(int i = number1; i<=number2; i++){
  16.             for(int j=number1; j<=number2; j++){
  17.                 if(i+j == magicNumber){
  18.                     counter+=1;
  19.                     n1 = i;
  20.                     n2 = j;
  21.                     checkPoint = true;
  22.                 }else{
  23.                     negativeCounter+=1;
  24.                 }
  25.                 if(checkPoint == true){
  26.                     break;
  27.                 }
  28.             }
  29.             if(checkPoint == true){
  30.                 break;
  31.             }
  32.         }
  33.  
  34.         if(counter!=0){
  35.             System.out.printf("Combination N:%d (%d + %d = %d)", counter+negativeCounter, n1, n2, magicNumber);
  36.         }else{
  37.             System.out.printf("%d combinations - neither equals %d", negativeCounter, magicNumber);
  38.         }
  39.     }
  40. }
  41.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×