DALLASCAO.COM

Site of Cao Shouguang, English to Chinese translator


Warning: Missing argument 1 for shapeshifter_archive_page_title(), called in /var/www/dallascao.com/en/wp-content/themes/shapeshifter/category.php on line 10 and defined in /var/www/dallascao.com/en/wp-content/themes/shapeshifter/includes/functions-do-actions.php on line 142

Category: World Wide Web

static method

static method
public class SavingsAccount { public static void main(String[] args) { AccountCaculation myAccount = new AccountCaculation(1000).deposit(2000); AccountCaculation yourAccount = new AccountCaculation(2000).deposit(5000); myAccount.printBalance(); yourAccount.printBalance(); System.out.println(AccountCaculation.totalBalance); System.out.println(AccountCaculation.usd2Rmb(myAccount.balance)); } } class AccountCaculation { int balance; static int totalBalance; // static method is per class and cannot access object variables static int usd2Rmb (int usd) { //can access class variables […]Read More

public class and class

public class and class
public class SavingsAccount { public static void main(String[] args) { AccountCaculation myAccount = new AccountCaculation(1000).deposit(2000); AccountCaculation yourAccount = new AccountCaculation(2000).deposit(5000); myAccount.printBalance(); yourAccount.printBalance(); System.out.println(AccountCaculation.totalBalance); } } class AccountCaculation { /** * output: * * 3000 * 7000 * 10000 */ int balance; static int totalBalance; AccountCaculation(int balance) { this.balance = balance; } AccountCaculation deposit(int amount) { […]Read More

Learn java: static variable

Learn java: static variable
public class Car { /** * Car.counter will output 2 */ String make; String model; int numDoors; static int counter; // constructor, applying to all cars Car(String make, String model, int numDoors) { this.make = make; this.model = model; this.numDoors = numDoors; counter++; } //constructor set default numDoors to 4 Car(String make, String model) { […]Read More

Test if a variable is number in bash

Test if a variable is number in bash
Among the solutions provided at stackoverflow.com, I like this one the most: var=a if [ "$var" -eq "$var" ] 2>/dev/null; then echo number else echo not a number fi 2 means the standard error output. If $var is a number, [ “$var” -eq “$var” ] will not output and error message. And an error message […]Read More

split string in Bash

split string in Bash
emails="email1@gmail.com;email2@gmail.com;email3@gmail.com" emails=${emails//;/ } #replace ; with space arr_emails=($emails) # put them into an array for item in ${arr_emails[@]}; do echo $item done In fact this works also. You don’t really need arrays emails="email1@gmail.com;email2@gmail.com;email3@gmail.com" emails=${emails//;/ } #replace ; with space for item in $emails; do echo $item done But with using arrays, you can do many […]Read More