Skip to main content

Posts

Showing posts from May, 2015

Python: calculating the area of circle

You can calculate the area of circle with and without using any variable. Both of these approaches are discussed below. Without using variable:- print (22.0 / 7) * (float(raw_input("Enter radius of the circle: ")) ** 2) With variable:- radius = float(raw_input("Enter radius of the circle: ")) print (22.0 / 7) * (radius ** 2)

Java implementing stack with custom class

If you want to create a custom class to implement stack in java, you can do something like this:- import java.util.ArrayList; import java.util.List; interface StackList<T> {     public boolean push(T data);     public T pop();     public int size(); } public class Stack<T> implements StackList<T> {     private final int max;     private int top = -1;     private final List<T> stack;     public Stack(int size) {         max = size - 1;         stack = new ArrayList<>(size);     }     public boolean push(T data) {         if (top <= max) {             top += 1;             stack.add(top, data);   ...