fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception{
  10. noFive(1,60);
  11.  
  12. }
  13.  
  14.  
  15. public static int noFive(int start, int end) {
  16.  
  17. ArrayList<Integer> arr = new ArrayList<Integer>();
  18. int result = end - start + 1;
  19.  
  20. for (int i = start; i <= end; i++) {
  21. arr.add(i);
  22. }
  23.  
  24. for (Integer i : arr) {
  25. if (!(i % 5 == 0) && hasFive(i)) { //my problem is here i try to do this but i know this does not eliminate numbers such as 51, 52, 53 etc.
  26. result--;
  27. System.out.print(i+",");
  28. }
  29. }
  30.  
  31. System.out.println(result);
  32. return result;
  33. }
  34.  
  35. private static boolean hasFive(int num) {
  36. int rem;
  37. while (num > 0) {
  38. rem = num % 10;
  39. if (rem == 5)
  40. return true;
  41. num = num / 10;
  42. }
  43. return false;
  44. }
  45. }
Success #stdin #stdout 0.09s 35972KB
stdin
Standard input is empty
stdout
51,52,53,54,56,57,58,59,52