Tag Archives: java

Double Ended Queue implementation in Java, and Operations run in O(1) time

public class Main {     /**      * @param args      */     public static void main(String[] args) {     Deque<Integer> Q = new Deque<Integer>(6);     try {         Q.addFirst(3);         System.out.println(Q);         Q.addFirst(5);         System.out.println(Q); … Continue reading

Posted in Code samples | Tagged | Leave a comment

Greatest Common Divisor : Java

/** * Gets GCD between two positive integers. * source: http://www.victorbyte.net * Returns int value */ public static int getGCD(int numA, int numB) { if(numA < numB) { int temp = numA; numA = numB; numB = temp; } if( … Continue reading

Posted in Code samples | Tagged | Leave a comment

Check for truth in a predicate : Java

/** * Checks for truth in a predicate. * http://www.victorbyte.net/ * Returns boolean value */ public static boolean forEachPredicate(double [] set_S) { for(double x:set_S) if(!(Math.pow(x,2.0) >= x)) //predicate return false; return true; } public static boolean negateForEachPredicate(double [] set_S) { … Continue reading

Posted in Code samples | Tagged | Leave a comment

Get highest number in a Java array.

/** * Checks for the highest int in an int array. * http://www.victorbyte.net/ * Returns int value */ public static int getMaxInArray(int[] array) { int max = array[0]; for(int i: array) max = max > i ? max : i; … Continue reading

Posted in Code samples | Tagged | Leave a comment

Java asterix pyramid

import java.util.Scanner; /** * * @author blogger.victorbyte.net * 30/08/2010 */public class Main { static String outPut = “”; static int errorLimit = 0; static Scanner userInput = null; static int getIntegerInput() { int value = 0; userInput = new Scanner(System.in); … Continue reading

Posted in java | Tagged | Leave a comment