Test your Java programming Skills!


There a nice little site which allows you to test and refresh your Java Programming skills by giving you a series of challenges to solve. I found it quite interesting. Although it’s does not completely covers all the aspects of java programming (e.g. the OOP concepts) but normal coding concepts which involves using control statements, arrays, string processing etc. are nicely covered.

Here is the link- http://javabat.com/

(I tried to solve each one of them with a single line of code and was successful for most of the easier problems. Try out and see if it is possible for you.) Leave a comment if help is needed.

44 comments so far

  1. Sujit on

    btw did u try Spring Framework ?

    its very nice to make web based application..

  2. Fr0z3n on

    No but i will look into it.
    Have you heard of OpenLaszlo.

  3. Amit on

    JFace is also a good Frame Work to work with JSPs and servlets.
    Raghav is doing btp – building web application in Spring Framework

  4. Fr0z3n on
  5. Simba on

    Yea nice problem: took time but finally able to solve it
    Here is solution:
    return str.length()

  6. Fr0z3n on

    how is that giving you the correct answer. :S

  7. Simba on

    this is not the answer i am unable to post it correctly coz of lack of my understanding in using tags provided by wordpress :S

  8. Fr0z3n on

    Ok. let me try posting the code.

    return str.charAt(0) + (str.length() > n : everyNth(str.substring(n), n) : "");

  9. Simba on

    return str.length() <= n ? str.substring(0,1):str.substring(0,1) + everyNth(str.substring(n),n);

  10. Simba on

    this is similar as top just remove str.substring(0,1) out and make it str.charAt(0). We used skew conditions and so are the statements.

  11. Simba on


    return str.length() <= n ? str.substring(0,1):str.substring(0,1) + everyNth(str.substring(n),n);

  12. Anil Kishore on

    Very nice solution.. didn’t think of recursion ..:(
    .
    How did u do this in 1line? I got it πŸ™‚
    “Given two temperaturessay t1,t2, return true if one is less than 0 and the other is greater than 100.”

  13. Fr0z3n on

    simple

    return (t1 < 0 && t2 > 100) || (t2 < 0 && t1 > 100)

  14. Rohit on

    Yeah !!

    My code wrkin too….. nice problem…. took sum time [:(]

    i had the same sol as Fr0z3n [:)]

  15. Rohit on

    HELP ME OUT !!!

    y s ths code nt wrkin for the stringE problem…??

    return (str.length() – ((str.replace(‘e’,’ ‘)).trim()).length() >= 1) && (str.length() – ((str.replace(‘e’,’ ‘)).trim()).length()

  16. Rohit on

    return (str.length() – ((str.replace(‘e’,’ ‘)).trim()).length() >= 1) && (str.length() – ((str.replace(‘e’,’ ‘)).trim()).length()

  17. Rohit on

    lo ab yeh code kyon nahi paste ho raha !!! 😦

  18. Rohit on

    jst add the followin code to wht I hve pasted at 5:51 am

  19. Rohit on

    [less than equal to] 3 ) ? true : false;

  20. Fr0z3n on

    which problem. i dont find any stringE problem. please give the link. And for less than type “& lt ;” without spaces and quotes.

  21. Fr0z3n on

    Found it now.
    It is working for me.
    Please check that you are writing everything correctly. (Note: you should replace ‘e’ with a blank character ” and not a space ‘ ‘)
    Also you don’t need to use trim() i guess.

  22. Simba on

    @ Rohit

    You are using wrong key expressing character (`) instead of (‘)
    check your code again

  23. Fr0z3n on

    that character is the problem due to posting here and not actually written by him.

  24. Simba on

    i checked this out that logic wont work cox of trim() method removes leading and trailing spaces not spaces in between the string.
    Nice try (Y)

  25. Fr0z3n on

    Thats the point. No need of replacing ‘e’ with a space. Just replace with a blank character ”.

  26. Simba on

    try this
    return (str.length() - str.replaceAll("e","").length() >= 1 &&
    str.length() - str.replaceAll("e","").length() <= 3);

  27. Fr0z3n on

    I used this:
    return (str.length() - str.replace("e","").length() >= 1 &&
    str.length() - str.replace("e","").length() <= 3);

  28. Fr0z3n on

    try solving some harder ones in one line. These are easier to solve. The harder one will require use of recursion as the one (everyNth) posted by me.

  29. Rohit on

    Yeah .. this is a good site… I ‘ll definitely spend time a brush up my programming skills by solving some gud 1s specially the recursion 1s…….

  30. Anil Kishore on

    β€œGiven two temperaturessay t1,t2, return true if one is less than 0 and the other is greater than 100.”
    .
    Froz3n replied
    “simple
    return (t1 100) || (t2 100)”
    .
    I got a still better solution..(i guess) ..

    return (t1*t2

  31. Anil Kishore on

    OOPS!!! I could get the characters printed 😦
    here it goes

    return (t1*t2 lessthan -101);

  32. Fr0z3n on

    consider when t1 = 90 && t2 = -2. Your solution will return me true which is wrong. You may have passed the test cases on the site, but the solution is wrong.

  33. AnilKishore on

    ya… sorry .. a bit over confident 😦
    .
    Can we create arrays in return statement?? Then how to solve this??
    [link] http://javabat.com/prob?id=Array1.makeEnds [/link]

  34. Fr0z3n on

    yes we can. like this. Try others from the arrays as they are almost same.
    return new int[]{nums[0], nums[nums.length-1]};

  35. AnilKishore on

    Hi !! I just got this ( http://javabat.com/prob?id=Logic.makeBricks ) in a single line πŸ™‚
    Who else got it ??

  36. Simba on

    nice problem
    solution:

    public boolean makeBricks(int small, int big, int goal) {
    return small >= goal ? true : ( (big > 0 && goal >=5) ? makeBricks(small, big-1, goal-5):false);
    }

    Whats ur solution

  37. Simba on

    non-Recursive solution

    return goal/5 <= big ? goal%5<=small : (goal-5*big)<=small;

  38. AnilKishore on

    Mine is….
    return (big >= 0) ? (((goal – 5*big ) = 0) ? true : (makeBricks(small,big-1,goal))) : (false);
    .
    .
    Ur’s is better πŸ™‚

  39. AnilKishore on

    sorry.. i couldn’t get the right characters printed here 😦
    ((goal – 5*big ) = 0).. should b replaced with ..
    ” ( ( ( goal – 5 * big ) = 0 )

  40. AnilKishore on

    lol πŸ˜€ ….. sorry once again …
    Can any1 help me 😦 .. Is thr any syntax to follow to get
    the code posted here ..??

  41. Simba on

    this is test πŸ˜›
    put all ur code in between <code><\code> tag

  42. Simba on

    this is test πŸ˜›
    do use ‘& lt ;’ (without qoutes and spaces) for less than symabol in your code

  43. faithict on

    Hello,

    I just started on the first class of java here in this website and i am already having trouble with it. I took Java class like 3 years ago and now i am thinking of brushing up my java skills. This is what i did for the first question of the website on determine if it is a holiday. I am not sure where i had gone wrong in my code as i am getting compilation error. Any advice is greatly appreciate by me. Thank you!

    public boolean sleepIn(boolean weekday, boolean vacation) {
    if(weekday==false && vacation==false)
    {
    boolean test = true;
    return test;
    }
    if(weekday==true && vacation==false)
    {
    boolean test=false;
    return test;
    }
    if(weekday==false && vacation==true)
    {
    boolean test = true;
    return test;
    }
    }

    • Yoshi on

      faithict try this…

      the ! means not

      public boolean sleepIn(boolean weekday, boolean vacation) {
      if (!weekday || vacation){
      return true;
      }
      else {
      return false;
      }

      }


Leave a reply to Fr0z3n Cancel reply