Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. package wyjatki;
  2.  
  3. public class Test {
  4.  
  5. public int daysToHours(int days){
  6.  
  7.  
  8. if (days < 0) {
  9. throw new IllegalArgumentException("Day must be >= 0: " + days);
  10. }
  11.  
  12. return days*24;
  13.  
  14. }
  15.  
  16. public static void main(String[] agrs){
  17.  
  18. Test t = new Test();
  19. int days = 0;
  20.  
  21. for(String strDays: agrs){
  22.  
  23. try{
  24. days = Integer.parseInt(strDays);
  25. System.out.println(days + " dni to " + t.daysToHours(days) + " h.");
  26. }
  27. catch (NumberFormatException ex){
  28. System.out.println(ex.getMessage());
  29. ex.printStackTrace();
  30. }
  31. catch (IllegalArgumentException ex){
  32. System.out.println(-days + " dni to " + t.daysToHours(-days) + " h.");
  33. }
  34. finally {
  35. System.out.println();
  36. }
  37. }
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement