Problem solving using java programming