Introduction to Java Programming Lecture 8 Flow Control : while do-while and for loops.

Slides:



Advertisements
Similar presentations
Introduction to Java Programming Lecture 10 Method Benefits, Declaring, and Calling Methods.
Advertisements

10 Macros.  Lisp code is expressed as lists, which are Lisp objects  This makes it possible to write programs that would write programs  This lecture.
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
Introduction to Java Programming Lecture 13 Classes I OO Programming.
Mathcad 基本認識 再mathcad中等於(=)的符號有區分為三種: 第一種:冒號等於(:=)是代表我們要定義ㄧ個參數
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
社研法助教課, 2007/04/11 如何閱讀 SPSS 圖表 (迴歸分析篇) By 黃昱珽. 小考題目 大華用 SPSS 得到以下的資料: (圖表見下面) 說明 : BABYMORT = 嬰兒死亡率, GDP_CAP = 一國國民生產毛額, LIT_FEMA = 女性識字率。 資料來源 : 聯合國,
亂數產生器安全性評估 之統計測試 SEC HW7 姓名:翁玉芬 學號:
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
JAVA 程式設計與資料結構 第二章 JAVA 程式基本概念及操作. 第一個程式 /* * 這是第一個程式 (FirstP.java) */ class FirstP{ public static void main(String args[]){ System.out.println("Whatever.
Multidimensional Array Outline Two-Dimensional Arrays Lengths of Two-Dimensional Arrays Multidimension Arrays [Sample code]
第 4 章 迴歸的同步推論與其他主題.
4-1 循序結構 4-2 選擇結構 4-3 重複結構 4-4 其他迴圈相關敘述 4-5 本章綜合練習
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
例外處理. 內 容 大 綱 例外的產生 捕捉例外 丟出例外 例外的產生 (1/4) 一般常見的執行時期錯誤包括整數除法分母為 0(divide by zero) ,陣列索引值越限 (array index out of range) ,輸入輸出錯誤 (I/O error) 、檔案 不存在或無法存取.
1 Introduction to Java Programming Lecture 7 Flow Control : Boolean expressions and the if statement.
Canonical Correlation 典型相關 目標 1 – 決定兩組變數 ( 對相同事務的衡量 ) 是否獨立, 或決定這兩組變數之間關係的強度 –Example: Y1+Y2+…+Ym=X1+X2+…Xn ( 一般式 ) Y1, Y2,…Ym 是否與 X1, X2,..,Xn 有相關 / 無相關.
程式語言實習 - JAVA Class1 1. 介紹 Java 編寫、編譯、執行 2. 請同學完成作業二.
Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih.
Java class Outline for loop while loop do while loop How to choose? Nested loop.
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
Introduction to Java Programming Lecture 15 Objects and Classes.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
第 5 章 深入 Response 物件 製作. 網頁的轉向與強制輸出 - 讓網頁轉彎的 Redirect 敘述 運用 Response 物件的 Redirect 方法,將瀏覽器顯 示的網頁,導向至其他網頁,語法如下: Response.Redirect 網頁路徑與名稱 此網頁路徑與名稱  若是導向到同一台.
第 6 章 迴圈結構 6-1 計數迴圈 6-1 計數迴圈 6-2 條件迴圈 6-2 條件迴圈 6-3 巢狀迴圈 6-3 巢狀迴圈 6-4 While/End While 迴圈 6-4 While/End While 迴圈 6-5 跳出與繼續迴圈 6-5 跳出與繼續迴圈 6-6 錯誤處理 6-6 錯誤處理.
Introduction to Java Programming Lecture 10 Array I Declaring, Creating, and Initializing Arrays.
類別函式庫. Java Bean 一個單獨的 AWT 元件都是一個 bean. Java Bean 也有一個 bean 的 class 可繼承, 但是並不強 迫一定要繼承. Bean 的結構 Properties 屬性 : 描述 bean 的屬性 如顏色, 大小,label 等. 透過一對 methods.
Introduction to Java Programming Lecture 19 JAVA GUI Programming.
第 10 章 視窗應用程式的工具列與 功能表 10-1 主功能表控制項 10-1 主功能表控制項 10-2 快顯功能表控制項 10-2 快顯功能表控制項 10-3 工具列控制項 10-3 工具列控制項 10-4 狀態列控制項 10-4 狀態列控制項 10-5 字型與色彩對話方塊 10-5 字型與色彩對話方塊.
Waves in string using Diamond rule and Mathematica software
資料結構實習-一 參數傳遞.
第 5 章 選擇控制項與條件敘述 5-1 結構化程式設計 5-1 結構化程式設計 5-2 關係與邏輯運算子 5-2 關係與邏輯運算子 5-3 簡單的條件敘述 5-3 簡單的條件敘述 5-4 選擇控制項 5-4 選擇控制項 5-5 巢狀條件敘述 5-5 巢狀條件敘述 5-6 多選一條件敘述 5-6 多選一條件敘述.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
第 9 章 TSR 程式基本教練. 本章提要 TSR 程式 以熱鍵 (Hot key) 叫用 TSR 程式 Clock 中斷 int 08h 、 int 1ch DOS reentrant 的問題 有用的 TSR 程式.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
Chapter 6 線性規劃 緒言 如何在有限的經濟資源下進行最有效的調配與 選用,以求發揮資源的最高效能。此問題愈來 愈受到重視,也就是以最低的代價,獲取最大 的效益。 茲列舉如下: – 決定緊急設備與人員的地點,使反應時間最短化。 – 決定飛機、飛行員、地勤人員的飛航最佳日程安排。
Windows Processing Design1 Chapter 1 C/C++ 概論 畫面輸出與鍵盤輸入 程式流程 程式流程的迴圈 函數的基礎 指標與陣列 字串 類別 利用 BCB 開發程式.
Chapter 3 Entropy : An Additional Balance Equation
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Chapter 2. Recurrence Relations (遞迴關係)
Introduction to Java Programming Lecture 9 Flow Control : while do-while and for loops II.
: Function Overloading ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11032:Function Overloading 解題者:許智祺 解題日期: 2007 年 5 月 8 日 題意:判對輸入之數字是否為.
JAVA 程式設計與資料結構 第十六章 Hash Tables. Introduction Hash Tables 結構為一個 Array ,稱之為 Bucket array 。 如果想要新增一個物件,要根據這個物件的特性 將其加入 Hash Table 內。 Bucket Array 用 A 來代替,其.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
5 重複迴圈 5.1 增減運算符號 增量運算符號 減量運算符號
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
第 6 章 迴圈結構 6-1 計數迴圈 6-1 計數迴圈 6-2 條件迴圈 6-2 條件迴圈 6-3 巢狀迴圈 6-3 巢狀迴圈 6-4 While/End While 迴圈 6-4 While/End While 迴圈 6-5 跳出迴圈 6-5 跳出迴圈 6-6 VB.NET 的錯誤處理 6-6 VB.NET.
Introduction to Java Programming Lecture 12 Method Benefits, Declaring, and Calling Methods.
函式 Function 東海大學物理系‧資訊教育 施奇廷. 函式簡介 當程式越來越大、越複雜時,程式的維護、 除錯會變得更困難,此時必須引入函式來 簡化程式或將程式分段,將程式重複的部 分改寫為函式,將程式「模組化」 這種作法有下列優點:節省程式發展的時 間、邏輯容易瞭解、程式容易除錯、可分 工合作完成程式.
Visual C++重點複習.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
第 5 章 選擇控制項與條件敘述 5-1 結構化程式設計 5-1 結構化程式設計 5-2 關係與邏輯運算子 5-2 關係與邏輯運算子 5-3 簡單的條件敘述 5-3 簡單的條件敘述 5-4 選擇控制項 5-4 選擇控制項 5-5 巢狀條件敘述 5-5 巢狀條件敘述 5-6 多選一條件敘述 5-6 多選一條件敘述.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
C 語言練習題 2010/12/2. C 程式的格式 一、 C 程式的格式 (1). /* …. */ 是 C 程式的 ______ main() 的內容是由敘述構成的 (2). 敘述要以 __ 為結束符號 (3). 變數、函數都要做 ____ 的宣告 (4). ‘=’ 是 ____ 用的算符 (5).
7.4 程式範例 在螢幕上寫出“Hello” 的程式 (參考 code/pep-p200.odc).
What is static? CS340100, NTHU Yoshi. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1;
 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
第8章 字串與陣列 8-1一維陣列的處理 8-2 字串處理 8-3 多維陣列的處理 8-4 動態陣列與參數傳遞 8-5 陣列排序與搜尋.
6 使用者函數 6.1 函數定義 宣告函數 呼叫函數 呼叫多個函數 6-6
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2009.
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
VHDL語法(3).
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
C++ Control Structures 程式的控制、運算、判斷跟你之前學過的程式語言是類 似的,所以這裡我們只用程式碼來說明。 你應該而且必須能看得懂這些程式 !!
Chapter 4 – C Program Control
南台科技大學 資訊工程系 Arduino 與電腦端互動設計之三 報告人:洪賢麟 指導老師:李育強 日期: 2013/11/20 報告人:洪賢麟 指導老師:李育強 日期: 2013/11/20.
PHP5&MySQL 程式設計 第 3 章 控制結構. 3-1 認識控制結構 判斷結構 (decision structures) 判斷結構 (decision structures) if (if … 、 if … else … 、 if … elseif … ) if (if … 、 if …
Presentation transcript:

Introduction to Java Programming Lecture 8 Flow Control : while do-while and for loops

While loop Example : int i = 0; while (i < 100) { System.out.println("Welcome to Java!"); i++; } Syntax ( 語法 ) : while (boolean_expression) { // statement_list; } 1. Initialization 初始值 4. Update: In this case, you can use either the pre or post increment operator. 變數值的改 變 2. Test Condition 判斷條件式 3. Loop body 迴圈主敘述

Do - while loop Syntax ( 語法 ) : do { // statement_list 至少執行一次 ; } while ( boolean_expression ); int i = 0; do { System.out.println("Welcome to Java!"); i++; } while (i<100); 1. Initialization 4. Test Condition 3. Update: In this case, you can use either the pre or post increment operator. 2. Loop body

Comparing while and do-while int i = 0; while (i < 100) { System.out.println("Welcome to Java!"); i++; } int i = 0; do { System.out.println("Welcome to Java!"); i++; } while (i<100);

Basic For Loop Example : ( 我們較常使用 for 來寫固定次數的迴圈 ) int counter; for (counter =1; counter <= 100; counter++) System.out.println ("Welcome to Java! ” + counter); 1. initialization 2. Test Condition 4. Update: Update the value. Note that each section is separated by a semicolon. Syntax ( 語法 ) : for(initialization; test condition; update expression){ //loop body; } 3. Loop body

Comparing While and for loops 可用 while 寫的迴圈,用 for 也寫得出來,反之亦然 int i = 0; while (i < 100) { System.out.println("Welcome to Java! ” + i); i++; } int i; for (i = 0; i < 100; i++) { System.out.println("Welcome to Java! ” + i); }