Skip to content

Instantly share code, notes, and snippets.

@0x000000AC
0x000000AC / BabylonianSqrt
Created June 2, 2012 11:51
Java Implementation of Babylonian Square Root Algorithm
/* The reason I created this was two-fold. 1. To learn Java 2. To learn about numerical analysis and numerical methods of arithmetic.
This code shows that the Babylonian Method of computing square roots is as accurate as the Java numerical method using sqrt() after as few
as 10 iterations for numbers within the limits of a double. I'm certain that it can be improved (and I have no vanity of authorship i.e., I welcome
criticism aaron.paul.clark@gmail.com). I love learning and sharing what I find, if you have some math-related code you're itching to share please
let me know!
There are numerous methods for computing square roots (http://en.wikipedia.org/wiki/Methods_of_computing_square_roots).
"The basic idea is that if x is an overestimate to the square root of a non-negative real number S then S/x will be an underestimate and so the average
of these two numbers may reasonably be expected to provide a better approximation."
@0x000000AC
0x000000AC / BabylonianSqrt5.java
Created June 2, 2012 12:12
Babylonian Algorithm for Square Roots in Java
/* The reason I created this was two-fold. 1. To learn Java 2. To learn about numerical analysis and numerical methods of arithmetic.
This code shows that the Babylonian Method of computing square roots is as accurate as the Java numerical method using sqrt() after as few
as 10 iterations for numbers within the limits of a double. I'm certain that it can be improved (and I have no vanity of authorship i.e., I welcome
criticism aaron.paul.clark@gmail.com). I love learning and sharing what I find, if you have some math-related code you're itching to share please
let me know!
There are numerous methods for computing square roots (http://en.wikipedia.org/wiki/Methods_of_computing_square_roots).
"The basic idea is that if x is an overestimate to the square root of a non-negative real number S then S/x will be an underestimate and so the average
of these two numbers may reasonably be expected to provide a better approximation."
@0x000000AC
0x000000AC / BabylonianSqrt6.java
Created June 2, 2012 15:05
Babylonian Algorithm for Square Roots in Java no comments and JOptionPane
import javax.swing.JOptionPane;
import java.io.*;
import static java.lang.Math.*;
public class BabylonianSqrt6 {
public static void main(String[] args) {
String S;
S = JOptionPane.showInputDialog(null, "Enter a Whole Integer");
int SigFigs = 0;
@0x000000AC
0x000000AC / cisco1-confg.txt
Created June 7, 2012 22:05
Cisco Config Radius Win2k8
!
! Last configuration change at 22:42:44 UTC Thu Jun 7 2012 by joe
upgrade fpd auto
version 15.1
service timestamps debug datetime msec
service timestamps log datetime msec
service password-encryption
!
hostname cisco1
@0x000000AC
0x000000AC / HelloGUI
Created November 30, 2012 20:41
Hello World using the JOptionPane
/***********************************************
* HelloGUI.java
* Aaron P. Clark
*
* One of the last programs of the chapter. Exhibits
* the use of the JOPtionPane GUI
***********************************************/
import javax.swing.JOptionPane;
public class HelloGUI
@0x000000AC
0x000000AC / CirclePrompt.java
Created November 30, 2012 20:50
Ch. 2 of Book, explores using java.util.Scanner and checks for a favorite shape.
/***********************************************
* CirclePrompt.java
* Aaron P. Clark
*
* Created to understand java.util.Scanner and Ch 2.
* shows the area of a circle if you say it's your
* favorite shape when prompted. See P.32 in our
* text for the pseudocode
***********************************************/
@0x000000AC
0x000000AC / HappyBirthday.java
Created November 30, 2012 21:12
Prints "happy birthday" 100x based on a counter in a while loop
/***********************************************
* HappyBirthday.java
* Aaron P. Clark
*
* Based on the pseudocode while loop on p.37 in Ch 2.
* prints "Happy birthday!" 100x
***********************************************/
public class HappyBirthday
{
@0x000000AC
0x000000AC / printLoop.java
Created November 30, 2012 21:19
I wanted to figure out how to print something a given number of times with a for loop
/***********************************************
* printLoop.java
* Aaron P. Clark
*
* Created from pseudocode in Ch. 2 of Park Univ.
* book. I wanted to figure out how to print something
* a given number of times.
***********************************************/
// Created from pseudocode in Ch. 2 of Park University book.
@0x000000AC
0x000000AC / whileLoop.java
Created November 30, 2012 21:35
Created this to figure out accepting user input in a while loop
/***********************************************
* whileLoop.java
* Aaron P. Clark
*
* I created this for Park programming calss to learn
* how to accept command-line input in a loop
***********************************************/
import java.util.Scanner;
public class whileLoop
@0x000000AC
0x000000AC / WhileLoopSentinalValue.java
Created November 30, 2012 21:38
Uses a "sentinal value" to exit the loop. The program poorly creates an average score.
/***********************************************
* WhileLoopSentinalValue.java
* Aaron P. Clark
*
* Based on the pseudocode while loop on p.40 in Ch 2.
* Takes scores and computes average.
***********************************************/
import java.util.Scanner;