Advertisement
Guest User

CodCodrin

a guest
Jan 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public static int SumaNumar(String textDate){
  2. String pattern = "sysdate";
  3. int daysCalc = 0;
  4. String operations = "";
  5. int numarFormat = 0;
  6. int semn=1;
  7. int indexSysdate = textDate.indexOf(pattern);
  8. int start = indexSysdate + pattern.length();
  9. System.out.println("start: " + start);
  10.  
  11. if(indexSysdate != -1){
  12. operations = textDate.substring(start);
  13. operations.trim();
  14. System.out.println("Numarul: " + operations);
  15. for(int i = 0;i<=operations.length()-1;i++) {
  16.  
  17. char iterate = operations.charAt(i);
  18. int gasit = 0;
  19. int gasitnr = 0;
  20.  
  21. if(Character.isDigit(iterate)){
  22. gasit = Character.getNumericValue(iterate);
  23. numarFormat = numarFormat * 10 + gasit;
  24. System.out.println("Numarul: " + numarFormat);
  25. }
  26.  
  27. //+234-32-42+4242
  28. if(Character.toString(iterate).equals("+")) {
  29. gasitnr = numarFormat;
  30. daysCalc += gasitnr*semn;
  31. numarFormat = 0;
  32. System.out.println("Adunarea: " + daysCalc);
  33.  
  34. }
  35.  
  36. //+234-32-42+4242
  37. if(Character.toString(iterate).equals("-")) {
  38. semn = -1;
  39. gasitnr = numarFormat;
  40. daysCalc += gasitnr*semn;
  41. numarFormat = 0;
  42. System.out.println("Scaderea: " + daysCalc);
  43. }
  44.  
  45.  
  46. }
  47. }
  48. return daysCalc;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement