MatchStick Game 3

Description:     Program for matchstick game being played between the computer and the user.It ensures that computer always wins. Rules for the games are as follows:            1. Number of matchsticks are entered by user.            2. The computer asks the player to pick 1,2 or 3 matchsticks. ...

Log4j Example

Description :  Log4j Example with BasicConfigurator and PropertyConfigurator  Java /*>>>>>>>>>>>>>>>>Program1 with BasicConfigurator<<<<<<*/ /*>>>>>>>>>>>>>>>>SampleLog4j.java<<<<<<<<<<<<<<<<<<*/ package com.example; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; public class SampleLog4j { static final Logger logger = Logger.getLogger(SampleLog4j.class); public static void main(String... args) { BasicConfigurator.configure(); Logger.getRootLogger().setLevel(Level.DEBUG); System.out.println(logger.isDebugEnabled()); logger.debug("Sample debug message"); logger.info("Sample info message"); logger.warn("Sample warn message"); logger.error("Sample error message"); logger.fatal("Sample fatal message"); } ...

LinkedList in Java

Linked List implementation in Java… ====================Node.java===================== Java public class Node { int key; Node link; public void setKey(int key) { this.key = key; } public int getKey() { return this.key; } public void setLink(Node node) { this.link = node; } public Node getLink() { return this.link; } public static Node createNode(int key, Node link) { ...

JSch example

Description : This program will explode the myapp.tar present in myHome directory and then navigation will be moved to “scripts” directory, generated after exploding the tar and then run “ls” command   Input : hostname,username, password Output: output of each command will be printed to console   Java package com.coddicted.example; import java.io.InputStream; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSch; import ...

GCD recursively

 Description:          The following program takes two numbers as input and determines the Greatest Common Divisor for them using recursion.                             Primary Inputs:    Two numbers Primary Output:    Determine the Greatest Common Divisor for input numbers Platform Used:      JDK 1.6 with Notepad.    import java.io.*; class GCDRecurse { public static void main(String[] args) { Console con=System.console(); System.out.print("Enter the first number for finding GCD: ...

First and Last Day of Month

The following code enables you to find the first and last day of a month in your JAVA code. package others; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class DateTest { /** * @param args */ public static void main(String[] args) { Date dt = null; // Get the last day of Feb. 2012 dt ...

Vampire Numbers 1

Table of ContentsWhat are Vampire numbers?Java Description: The following programs finds out all the 4 digit Vampire numbers defined as follows: What are Vampire numbers? A vampire number has an even number of digits and is formed by multiplying a pair of numbers containing half the number of digits of the result. The digits are ...

File Splitter

 Description:          The following two programs split any specified file in size of specified size (in bytes).   Primary Inputs:    Name of the file to be divided and the desired size(in bytes) of the target parts. Primary Output:    File part(s) of the size specified in input. Platform Used:      JDK 1.6 with JCreator   //File Name: SplitFile.java //SplitFile.java //Contains the main function ...

File Merger

 Description:          The following two programs merge the pieces obtained from the splitting using File Splitter class.   Primary Inputs:    Name of the original file that was split using FileSplitter.java Primary Output:    Original File in its entirety. Platform Used:      JDK 1.6 with JCreator   //File Name: MergeFiles.java //Contains the main function for file merging //this file uses the FileMerger class import ...

Display numeric value in reverse order

Example: given a number say 7584, the program should display it in reverse order 4857. public class Reverse { public static void main(String args[]) { int i = 7584; Reverse r = new Reverse(); r.reverseNum(i); } public void reverseNum(int num) { if(num!=0) { System.out.print(num%10); num = num/10; reverseNum(num); } } }