Skip to content

Instantly share code, notes, and snippets.

View edolopez's full-sized avatar
🎯
Focusing

Eduardo Lopez De Leon edolopez

🎯
Focusing
View GitHub Profile
@edolopez
edolopez / Binary.java
Created March 2, 2014 22:34
Binary Search method in Java
public static int binarySearch(int numbers[], int key) {
// Select highest and lowest indexes on the array
int mid;
int low = 0;
int high = numbers.length - 1;
// Continue searching while low is still smaller than high
while (low <= high) {
mid = (low + high) / 2; // Binary partition
if (numbers[mid] > key) {
@edolopez
edolopez / Puppy.java
Created March 23, 2014 17:00
Puppy class and PuppyTest (with the main method), an example of Objects
public class Puppy {
// Instance Variables
int age;
String color;
String breed;
double weight;
String name;
public Puppy() {
name = "Default";
@edolopez
edolopez / Circle.java
Created March 24, 2014 14:34
Graphical Representation for OOP
// Reference for this Class:
// http://www.ntu.edu.sg/home/ehchua/programming/java/images/ExerciseOOP_Circle.png
//
public class Circle {
private double radius;
private String color;
public Circle() {
@edolopez
edolopez / ReadFile
Created April 7, 2014 13:29
An example of Reading a File with the Scanner Class
import java.io.*;
import java.util.Scanner;
public class ReadFile {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
Scanner file = new Scanner(new File("info.txt"));
int numLines = file.nextInt();
@edolopez
edolopez / NumbersInFile.java
Last active March 31, 2025 10:01
Example of writing and reading Text Files in Java
import java.io.*;
import java.util.*;
public class NumbersInFile {
public static void main(String[] args) throws IOException {
//
// READING FROM A FILE
//
try {
@edolopez
edolopez / Strings.java
Created April 9, 2014 13:58
Try-Catch block in Java, a simple example
import java.util.*;
import java.io.*;
public class Strings {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
try {
input.nextInt();
System.out.println("Thanks");
} catch (InputMismatchException e) {