Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package alg;
  2.  
  3. /**
  4. *
  5. * @author Bam
  6. */
  7. public class Main {
  8.  
  9. /*
  10. * x od 0 do range
  11. * y od -range do range
  12. */
  13. public static int range = 10000;
  14.  
  15. // ax +- by = result
  16. public static int a = 5;
  17. public static int b = 7;
  18. public static int result = 1829;
  19.  
  20. // jesli NWD nie jest podany musi rownac sie 0
  21. public static int NWD = 59;
  22.  
  23. /* znak rownania
  24. * 'p' plus
  25. * 'm' minus
  26. */
  27. public static char sign = 'p';
  28.  
  29. public static void main(String[] args) {
  30. for(int x = 0; x < range; x++)
  31. for(int y = -range; y < range; y++ ){
  32. int res = 0;
  33.  
  34. if( sign == 'p' ) res = a * x + b * y;
  35. else if( sign == 'm') res = a * x - b * y;
  36. else System.exit(0);
  37.  
  38. if( res == result ){
  39. if( NWD != 0 ){
  40. if( x % NWD == 0 && y % NWD == 0 )
  41. System.out.println("x: " + x + " | y: " + y + " |for: " + result);
  42. }else{
  43. System.out.println("x: " + x + " | y: " + y + " |for: " + result);
  44. }
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement