This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Puppy { | |
| // Instance Variables | |
| int age; | |
| String color; | |
| String breed; | |
| double weight; | |
| String name; | |
| public Puppy() { | |
| name = "Default"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.*; | |
| import java.util.*; | |
| public class NumbersInFile { | |
| public static void main(String[] args) throws IOException { | |
| // | |
| // READING FROM A FILE | |
| // | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
OlderNewer