Advertisement
Dilyana86

Untitled

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