Advertisement
nevenailievaa

09. Sum of Two Numbers

Mar 6th, 2024
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SumTwoNumbers {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner (System.in);
  8.  
  9.  
  10.             int startSmallNumberInput=Integer.parseInt(scanner.nextLine());
  11.             int finalBigNumberInput=Integer.parseInt(scanner.nextLine());
  12.             int magicNumber=Integer.parseInt(scanner.nextLine());
  13.  
  14.             int count=0;
  15.  
  16.             for(int small=startSmallNumberInput;small<=finalBigNumberInput;small++){
  17.                 for(int big=startSmallNumberInput;big<=finalBigNumberInput;big++){
  18.                     count++;
  19.                     if(small+big==magicNumber){
  20.                         System.out.printf("Combination N:%d (%d + %d = %d)",count,small,big,magicNumber);
  21.                         return;
  22.                     }
  23.                 }
  24.             }
  25.         System.out.printf("%d combinations - neither equals %d",count,magicNumber);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement