Advertisement
Ivakis

Two Numbers Sum

Sep 14th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int start = Integer.parseInt(scanner.nextLine());
  8. int end = Integer.parseInt(scanner.nextLine());
  9. int magicNum = Integer.parseInt(scanner.nextLine());
  10.  
  11. int count = 0;
  12.  
  13. for (int i = start; i >= end ; i--) {
  14. for (int j = start; j >= end ; j--) {
  15. count++;
  16. if(i + j == magicNum){
  17. System.out.printf("Combination N:%d (%d + %d = %d)",
  18. count,i,j,magicNum);
  19. return;
  20. }
  21. }
  22. }
  23. System.out.printf("%d combinations - neither equals %d", count, magicNum);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement