27
How To Program Ping-Lun Liao

How toprogram

Embed Size (px)

Citation preview

Page 1: How toprogram

How To Program

Ping-Lun Liao

Page 2: How toprogram

Outline

程式語言 「組成元素有什麼?」 「為什麼要有這些元素?」

如何去解程式問題的步驟 ( 如程式作業 ) 分析:問題的困難點、關鍵在那 設計:要用什麼 Data Structure 、 Algorithm 實作 Debug Source Code Version Control

實例講解

Page 3: How toprogram

Tool and Language

Tool: Eclipse Language: Java

Page 4: How toprogram

程式語言

Page 5: How toprogram

0x0008

Data

Data Type (Why)– Integer– Float-point– String– Literal

• 1234• 13.333• 'a', "string"

Array– Homogeneous

0x0016

0x0024

0x0032

0x00080x00080x0008

0x00160x0016

0x0024

0x0004

0x0008

0x0012

0x0016

0x00040x00040x0004

0x00080x0008

0x0012

‘C’

‘H’

‘A’

‘R’

Page 6: How toprogram

Control Structures

– Decision• if

• switch

– Loop• for

• while / do … while

– Jump• Goto

– Function

Page 7: How toprogram

if

truefalse

Page 8: How toprogram

比較兩數大小

truefalseA > B

A 比較大B 比較大

Page 9: How toprogram

switch

想想看 switch 要怎麼畫流程圖

Page 10: How toprogram

for / while

truefalse

Page 11: How toprogram

Summation

truefalse i <= n

sum = sum + i

Page 12: How toprogram

Summation

Another solution– 公式解

∑i=1

n

i=n×(n+1 )

2

Page 13: How toprogram

do … while

怎麼畫流程圖?

Page 14: How toprogram

Program = DS + ALG

Data Structure– Stack– Queue– …etc

Algorithm– Sort

• QuickSort• BubbleSort

– Search• BinarySearch• LinearSearch

– …etc

Stack

Queue

push

poppush

pop

Page 15: How toprogram

Example: Prime

判斷一個數是否為質數 求出小於n ( 小於 32767) 的所有質數

Page 16: How toprogram

Example: Diamond

* *** ***** ******* ********* *********** ************* *************** ************************************ ***************** *************** ************* *********** ********* ******* ***** *** *

Page 17: How toprogram

Example: Diamond2

* * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * *

Page 18: How toprogram

Example: Diamond3

********* ***************** *************** ************* *********** ********* ******* ***** *** *

* *** ***** ******* ********* *********** ************* *************** ***************** *********

Page 19: How toprogram

Example: Cross

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** *

Page 20: How toprogram

x

y

  ☆ ☆☆☆☆☆☆☆☆  ☆☆☆  ☆

Page 21: How toprogram

Example: ?

Page 22: How toprogram

Review & QA

Page 23: How toprogram

練習題 java console 跑馬燈

Page 24: How toprogram

Code Version Control

git github

Page 25: How toprogram

What’s next?

Object-Oriented Programming Swing Networking Thread ...

Page 26: How toprogram

Exercise: Longest Increasing Subsequence(LIS)

What’s LIS?– 4, 1, 3, 10, 7, 9, 8, 2, 5, 6

– (1, 3, 10) (3, 7, 9) (2, 5, 6)…

– (1, 3, 7, 9) is longest and the length is 4. Longest Increasing Subsequence

– Dynamic Programming

4, 1, 3, 10, 7, 9, 8, 2, 5, 61 1 2 3 3 4 4 2 3 4

Page 27: How toprogram

我的連絡方式 E-mail: pinglunliao [at] gmail [dot] com LINE: Holan.Liao