Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import java.util.Scanner;
  2. import static java.lang.Math.pow;
  3.  
  4. public class Pussel {
  5. public static void main(String[] args) {
  6. Scanner input = new Scanner(System.in);
  7. int x,y,n,k,i,j;
  8. int finalYears,finalDays,finalHours, finalMinutes,finalSeconds;
  9. double years,seconds,minutes,hours,days;
  10. double sec_hours = 3600.0;
  11. double sec_minutes = 60.0;
  12. double sec_years = 31556926.0;// 31536000.0;
  13. double sec_days = 86400.0;
  14. double time, sumK = 0.0,sumN = 0.0;
  15. boolean exit = true;
  16.  
  17.  
  18. do {
  19. System.out.println("Ange ett x och y varde mellan 1-60: ");
  20. x = input.nextInt();
  21. y = input.nextInt();
  22. if((x>= 1) & (x <= 60) & (y>= 1) & (y<= 60)) {
  23. exit = false;
  24. k = (2*x+2*y)-4;
  25. n = (x*y)-k;
  26. for(i=1; i <= k; i++) {
  27. sumK = sumK + pow(1.001,i);
  28. }
  29. for(j=1; j <= n; j++) {
  30. sumN = sumN + pow(1.01,j);
  31. }
  32. time = sumK + sumN;
  33. System.out.println(time);
  34.  
  35. years = time/sec_years;
  36. time = time % sec_years;
  37. finalYears = (int) years;
  38.  
  39. days = time/sec_days;
  40. finalDays = (int) days;
  41. time = time % sec_days;
  42.  
  43. hours = time/sec_hours;
  44. finalHours = (int) hours;
  45. time = time % sec_hours;
  46.  
  47. minutes = time/sec_minutes;
  48. finalMinutes = (int) minutes;
  49. time = time % sec_minutes;
  50.  
  51. seconds = time;
  52. finalSeconds = (int) time;
  53.  
  54. System.out.println(finalYears +" "+ finalDays +" "+ finalHours +" "+ finalMinutes +" "+ finalSeconds);
  55. }
  56.  
  57. else {
  58. System.out.println("Fel nummer, forsok igen!");
  59. }
  60. } while(exit);
  61.  
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement