Skip to content

Instantly share code, notes, and snippets.

View BalicantaYao's full-sized avatar

Balicanta BalicantaYao

View GitHub Profile
package hello;
public class OCR {
public static void main(String[] args)
{
String first = "1ba";
String second = "a1a";
boolean res = Ocr(first, second);
System.out.println(res);
@BalicantaYao
BalicantaYao / web.xml
Created December 3, 2017 07:29
web xml example
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>week3.SimpleServlet</servlet-class>
</servlet>
1.給予 int x,請計算 y 值,其公式如下:
y = 3 * x^2 若 x < -1
y = x^3 + 3 * x - 3 若 -1 <= x <= 1
y = 2 * x + 3 若 x > 1
2.給予三角形三邊長(int)a,b,c,請判斷是直角,銳角,鈍角,或非三角形.
(註:假設邊長排序結果,a <= b <= c,則
直角(right triangle): c*c = a*a + b*b
鈍角(obtuse triangle): c*c > a*a + b*b
銳角(sharp triangle): c*c < a*a + b*b
@BalicantaYao
BalicantaYao / 20180225 Java Homework
Last active March 4, 2018 01:17
20180225 Java Homework
1.(數列反印) 亂數產生10個介於2~2000的偶數,依序存到陣列內,再反印之,
輸出範例
原始數列: 250 1400 890 126 1844 734 182 1922 36 976
反印數列: 976 36 1922 182 734 1844 126 890 1400 250
2.(數列和) 亂數產生10個整數,值介於1-99之間,求10個整數和.
3.請寫一個 Method, 接收最大亂數值、最小亂數值產生一個落在範圍裡的亂數,並印出
public void printRandom(int max, int min){
}
public class Student{
// 靜態 -
int score = 0;
// 動態 -
public void play(int hours){
score = score - hours;
}
@BalicantaYao
BalicantaYao / 20180304 Java Homework
Created March 3, 2018 15:07
20180304 Java Homework
1.(戶頭)
實作一戶頭類別Account,內含私有餘額balance,型別實數,
對外提供如下公開方法:
public Account(double initialBalance) //建構子,含初始餘額
public void credit(double amount) // 存款,含存款金額
public double getBalance() // 讀出餘額,回傳餘額
測試時,可用建構子建立一個戶頭,初始餘額為50,先印餘額看對不對,
再存入25,印餘額看對不對.
註: 建構子若遇初始餘額<0,可一律設定為0.
package homework.week7;
public class Employee {
private String firstName;
private String lastName;
public Employee(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
1. 接收使用者輸入的數,直到使用者輸入 -1 為止,並將使用者過去輸入的數,全部一起於一列印出,並用空白分開。
- Scanner, nextInt
- ArrayList - 使用者輸入的數字存在這
- 透過 for 印出
2. 電腦產生 7 個 1 - 42 的亂數,並不得重覆。
- Random
- HashSet
public boolean isValidEmailAddress(String email) {
String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
Pattern p = Pattern.compile(ePattern);
Matcher m = p.matcher(email);
return m.matches();
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="13">
<profile kind="CodeFormatterProfile" name="Garmin" version="13">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>