Skip to content

Instantly share code, notes, and snippets.

View yukeehan's full-sized avatar

Yukee Han yukeehan

  • Ottawa
View GitHub Profile
clear all;
close all;
% Create some random data
s = [2 2];
x = randn(334,1);
y1 = normrnd(s(1).*x,1);
y2 = normrnd(s(2).*x,1);
data = [y1 y2];
@yukeehan
yukeehan / gist:aba339f4f49b2b66a03305eaa32cacaf
Created January 23, 2018 21:21
do-while loop to discard any unwanted character remaining in the input buffer
package chapter3;
public class TryThis3_2 {
public static void main(String args[])
throws java.io.IOException{
char choice,ignore;
do {
System.out.println("1.if 2.switch 3.for 4.while 5.do-while\nchooose one");
choice = (char)System.in.read();
class Queue{
char q[ ];
int putloc, getloc;
Queue(int size){
q = new char[size];
putloc = getloc = 0;
}
void put(char ch) {
public class SelfTest13 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] array = {2,7,4,32,67,12,1,48,26};
int max = array[0];
int min = array[0];
for(int v:array) { //for-each for loop
public class TryThis6_3Quicksort {
public static void main(String[] args) {
// TODO Auto-generated method stub
char a[] = {'d','x','a','r','p','j','i'};
int i;
System.out.println("Original array: ");
for(i=0; i<a.length; i++) {
class Stack1{
private char q[];
private int tos;
int length;
Stack1(int size){
q = new char [size];
tos = 0;
length = size;
}
enum TrafficLightColor{
RED, GREEN, YELLOW;
}
class TrafficLightSimulator implements Runnable{
private TrafficLightColor tlc; // holds the traffic light color
private boolean stop = false; // set to true to stop the simulation
private boolean changed = false; // true when the light has changed
TrafficLightSimulator(TrafficLightColor init) {
tlc = init;
public class GenQDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer iStore[] = new Integer[10];
GenQueue<Integer> q = new GenQueue<Integer>(iStore);
Integer iVal;
@yukeehan
yukeehan / TFDemo
Created May 16, 2018 21:02
Swing JBotton, JFrame , Jlabel and JTextFiled
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
@yukeehan
yukeehan / TFDemo
Created May 16, 2018 21:02
Swing JBotton, JFrame , Jlabel and JTextFiled
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;