Skip to content

Instantly share code, notes, and snippets.

View JiaruiTracy's full-sized avatar

JiaruiTracy JiaruiTracy

  • West Long Branch, NJ
View GitHub Profile
@JiaruiTracy
JiaruiTracy / ExponentialDistribution.java
Created September 26, 2017 22:21
The class to generate random number obey exponential distribution
package simulation.util;
import java.text.DecimalFormat;
/*
* The numbers generated by java Random is using Uniform Distribution.
* But recently, when I work on Timed-Petri net, it is better to use Exponential Distribution.
* Thus, I write a class which is like a exponential calculator.
*
* INPUT: lamda
@JiaruiTracy
JiaruiTracy / addTwoNumbers.java
Created August 1, 2017 23:38
[Leetcode445 Stack Solution]Add two numbers, 4 lines
/*
* This code is to describe how to use stack implement adding two numbers.
* The key is the while-loop in the addTwoNum() method.
*/
import java.util.*;
public class StackNumberApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
@JiaruiTracy
JiaruiTracy / sortedInsert.java
Created July 12, 2017 15:01
Using insertion sorting to insert some elements, every time inserts one value to the sorted array.
public void insert(int rand){
int cur = rand;
int j = num-1;
while(j>=0&&randNum[j]>cur){
randNum[j+1]=randNum[j--];
}
randNum[j+1]=cur;
num++;
}
@JiaruiTracy
JiaruiTracy / findRepeat.java
Created July 12, 2017 14:59
A quick way to calculate repeat times of each element in an array, which contains 100 random numbers between 0 and 30
package arr;
import java.util.Random;
public class arrTest {
public static void main(String[] args) {
int[] randNum = new int[100];
int[] count = new int[31];
@JiaruiTracy
JiaruiTracy / insertionSort.java
Created July 12, 2017 14:52
Insertion sorting
package arr;
public class insertionSort {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = {5,1,2,10,12,7,8,3,9,100};
sort(arr);
@JiaruiTracy
JiaruiTracy / Eclipse .jar using
Created February 23, 2017 21:09
About jdk on MAC
The issue came up when I import a external big project, some jar files could not be found. Different from Windows OS, Mac OS X doesn't need to deploy class path or JAVA_HOME, but as a new user of Mac I just make this convenience complex. To deal with the issue, I searched for "where is jdk on mac located", "where is Library file on mac".
It's hard to operate jdk on Mac, but also, after searching a lot of information, finally I realized that it is unnecessary to know where the jdk is and how to change it.
All settings have been deployed automaticly after downloading Eclipse, the additional things that developer needs to do is: if you realize that some .jar files are not included in your jdk /lib file while developing, just download the .jar file from internet and then click on Eclipse <Preference> --> <Java> --> <Installed JREs> --> select your JDK --> <Edit>, then you can see your JRE system libraries. If the jar you want doesn't exist there, click on <Add External JARs to the list>, go to your downloaded