Skip to content

Instantly share code, notes, and snippets.

@goldcode88
goldcode88 / 10return_multi_val.java
Last active April 2, 2017 02:13
Returning Multiple values in Java
// A Java program to demonstrate that a method
// can return multiple values of same type by
// returning an array
class Test
{
// Returns an array such that first element
// of array is a+b, and second element is a-b
static int[] getSumAndSub(int a, int b)
{
int[] ans = new int[2];
@goldcode88
goldcode88 / array_return.java
Last active April 2, 2017 02:14
array返回值
import java.util.*;
class Test {
public static int[] rotate90degrees(int[] v){
int[] w = new int[2];
w[0] = v[1];
w[1] = v[0];
return w;
}
@goldcode88
goldcode88 / 10error1.java
Last active April 2, 2017 02:14
ArrayList遍历的同时删除
ArrayList<String> list = new ArrayList<String>();
list.add("one");
list.add("two");
list.add("two");
list.add("two");
list.add("two");
for(int i=0;i<list.size();i++){
if(list.get(i).equals("two")){
list.remove(i);
}
@goldcode88
goldcode88 / 05basic.java
Last active April 2, 2017 02:15
ArrayList在内循环中删除 1.The iterators returned by this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. 参考:http://stackoverflow.com/quest…
import java.util.*;
public class ArrayListExamples {
public static void main(String args[]) {
// Creating an empty array list
ArrayList<String> list = new ArrayList<String>();
// Adding items to arrayList
list.add("Item1");
//Compares two {@code int} values numerically.
//The value returned is identical to what would be returned by:
public static int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
public class Program {
public static void main(String[] args) {
// Display common numeric types.
System.out.println(Character.TYPE);
System.out.println(Character.SIZE);
System.out.println((int) Character.MIN_VALUE);
System.out.println((int) Character.MAX_VALUE);
System.out.println(Integer.TYPE);
System.out.println(Integer.SIZE);
@goldcode88
goldcode88 / new_gist_file_0
Last active April 2, 2017 02:15
变量初始化例子
class Complex {
private double re, im;
//public int a,b,c=null; //fault
public int a,b,c; //correct
public String name,value=null;//correct
public Complex(double re, double im) {
this.re = re;
this.im = im;
a = 1;
@goldcode88
goldcode88 / Complex_test1.java
Last active April 2, 2017 02:16
问题1:如何重载toString 1.toString是Objects的内部函数,不需要显式继承就可以覆盖,当然显式继承也可以。 参见:http://www.geeksforgeeks.org/overriding-tostring-method-in-java/ 问题2: 2.为何重载了toString,println就会去调用它? 参见:http://stackoverflow.com/questions/29318996/the-connection-between-system-out-println-and-tostring-in-java ...calls at first String.valueOf(x) to get the printed object's stri…
// file name: Main.java
class Complex {
private double re, im;
public Complex(double re, double im) {
this.re = re;
this.im = im;
}
}
@goldcode88
goldcode88 / 0_reuse_code.js
Created April 1, 2017 01:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@goldcode88
goldcode88 / layout.kbd.json
Created December 11, 2016 10:08
Untitled Keyboard Layout
[
[
"Esc",
"!\n1",
"@\n2",
"#\n3",
"$\n4",
"%\n5",
"^\n6",
"&\n7",