Microsoft Word - 第3章.doc

Similar documents
untitled

新・解きながら学ぶJava

untitled

untitled

untitled

CC213

CHAPTER 1

untitled

Microsoft Word - 01.DOC

《大话设计模式》第一章

新版 明解C++入門編

CHAPTER VC#

Java

第一章 章标题-F2 上空24,下空24

C/C++ - 字符输入输出和字符确认

untitled

chp6.ppt

FY.DOC

Chapter 9: Objects and Classes

全国计算机技术与软件专业技术资格(水平)考试

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

新版 明解C言語入門編

C/C++ 语言 - 循环

C/C++ - 函数

C/C++语言 - 运算符、表达式和语句

nooog

新・解きながら学ぶC言語

第3章.doc

JavaIO.PDF

(Microsoft Word - \272\364\263q\245|\244A_ _\304\254\253\330\336\263__\272\353\302\262\263\370\247i.doc)

3.1 num = 3 ch = 'C' 2

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

untitled

新・明解C言語入門編『索引』

C/C++语言 - 分支结构

概述

EJB-Programming-4-cn.doc

CC213

C 1

(京)新登字063号

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

Microsoft Word - ch04三校.doc

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

PowerPoint Presentation

ebook39-5

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

C/C++语言 - C/C++数据

C H A P T E R 7 Windows Vista Windows Vista Windows Vista FAT16 FAT32 NTFS NTFS New Technology File System NTFS

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

untitled

四川省普通高等学校

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit


C/C++ - 字符串与字符串函数

Microsoft Word - PHP7Ch01.docx

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

基于CDIO一体化理念的课程教学大纲设计

C

Chapter 9: Objects and Classes

06 01 action JavaScript action jquery jquery AJAX CSS jquery CSS jquery HTML CSS jquery.css() getter setter.css('backgroundcolor') jquery CSS b

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

C C

附录J:Eclipse教程

untitled

2 WF 1 T I P WF WF WF WF WF WF WF WF 2.1 WF WF WF WF WF WF

_汪_文前新ok[3.1].doc

p-2.indd

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

C/C++程序设计 - 字符串与格式化输入/输出

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

EJB-Programming-3.PDF

c_cpp

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj

javaexample-02.pdf

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

エスポラージュ株式会社 住所 : 東京都江東区大島 東急ドエルアルス大島 HP: ******************* * 关于 Java 测试试题 ******

天仁期末個人報告1.PDF

untitled

ebook14-4

Microsoft Office SharePoint Server MOSS Web SharePoint Web SharePoint 22 Web SharePoint Web Web SharePoint Web Web f Lists.asmx Web Web CAML f

WWW PHP

C语言的应用.PDF

Microsoft PowerPoint - L17_Inheritance_v4.pptx

untitled

untitled

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

untitled

untitled

C/C++ - 文件IO

51 C 51 isp 10 C PCB C C C C KEIL

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2

(Microsoft Word - Motion Program \270\305\264\272\276\363 \307\245\301\366 \271\327 \270\361\302\367.doc)

Microsoft PowerPoint - ds-1.ppt [兼容模式]

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:

02

Strings

untitled

Transcription:

Java C++ Pascal C# C# if if if for while do while foreach while do while C# 3.1.1 ; 3-1 ischeck Test() While ischeck while

static bool ischeck = true; public static void Test() while (ischeck) ; ischeck while 51 3.1.2 statement-list; // statement-list statement-list 3-2 4 3 int firstnum secondnum total int firstnum, secondnum, total; firstnum = 100; secondnum = 10; total = firstnum * secondnum; 1000 3.1.3

52 static string name = "Jack"; double money = 300.23; const double radius = 3.14; const int size = 100; // // double // double // 3.1.4 C# num=2002 object o = new object() ++num --num num++ num-- count() if if switch 3.2.1 if if if if () true false if 3-1

53 3-1 if 3-3 @ 6 Console.Write(""); string username = Console.ReadLine(); Console.Write(" "); string userpass = Console.ReadLine(); if (username.contains("@")) Console.WriteLine(" "); if (string.isnullorempty(userpass) userpass.length < 6) Console.WriteLine(" 6 "); Console.ReadLine(); if @ IsNullOrEmpty() Length if 3-2 3-2 3.2.2 if if if if ( )

54 1 2 if true 1 2 if 3-3 3-3 if 3-4 5 12 DateTime dt = DateTime.Now; if (dt.hour > 5 && dt.hour < 12) Console.WriteLine(" "); Console.WriteLine(" "); DateTime.Now Hour if 3.2.3 if if if if C# if if if

if ( 1) 1 if( 2) 2... if ( n) n n+1 55 if if 1 true 1 if if true false n+1 3-4 3-4 if if 3-5 Console.WriteLine("=============== ================"); Console.WriteLine("1. \n2. \n3. \n4. "); Console.Write(" ");

56 int number = Convert.ToInt32(Console.ReadLine()); if (number == 1) Console.WriteLine(""); if (number == 2) Console.WriteLine(" "); if (number == 3) Console.WriteLine(""); if (number == 4) Console.WriteLine(" "); Console.WriteLine(" "); number if if 1 4 3-5 3-5 3.2.4 if if if if if if if if if if ( 1)

if ( 2) 1 2 if ( 3) 3 4 57 if if if if if if 3-6 3-6 if 3-6 5000 3 10 double price = 5000;

58 Console.Write(" "); int month = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("=1 =2"); int type = Convert.ToInt32(Console.ReadLine()); if (month >= 3 && month <= 10) // if (type == 1) // Console.WriteLine(" " + price * 0.6); // Console.WriteLine(" " + price * 0.5); // if (type == 1) // Console.WriteLine(" " + price * 0.9); // Console.WriteLine(" " + price * 0.8); price month type if if 3-7 3-7 3.2.5 switch if if if 10 20

switch switch switch if switch switch() case 1: 1; break; case 2: 2; break;... case n: n; break; default: n+1; break; 59 switch case case case default n+1 break switch 3-8 3-8 switch C# switch case case case

3-7 switch 60 Console.Write(" 0123 1 23 "); int monthday = Convert.ToInt32(Console.ReadLine()); int month = monthday / 100; int day = month % 100; string xingzuo = ""; switch (month) case 1: xingzuo = day < 21? "" : ""; break; case 2: xingzuo = day < 20? "" : ""; break; /* */ case 12: xingzuo = day < 22? "" : ""; break; Console.WriteLine("" + xingzuo); monthday month day switch case case 3-9 3-9 C# for while do while foreach 4

3.3.1 for for for (; ; ) 61 for 3-10 3-10 for 3-8 for 1 100 int totalsum = 0, oddsum = 0, evensum = 0; for (int num = 1; num <= 100; num++) totalsum += num; if (num % 2 == 0) evensum += num; oddsum += num; Console.WriteLine("1-100 " + totalsum + "\n1-100 " + oddsum + "\n1-100 " + evensum); 3 totalsum oddsum evensum

for num=1 num<=100 num 100 num++ num 1 if num 2 62 1-100 5050 1-100 2500 1-100 2550 if for 3-9 for Console.Write(""); int rows = Convert.ToInt32(Console.ReadLine()); Console.Write(""); int line = Convert.ToInt32(Console.ReadLine()); for (int i = 1; i <= rows; i++) for (int k = i; k <= rows; k++) Console.Write(" "); for (int j = 1; j <= line; j++) Console.Write("*"); Console.WriteLine(); rows line for for for for 3-11 3-11

3.3.2 while for C# while while 63 while ( ) while while 3-12 3-12 while 3-10 while 1 100 5 int number = 5; int total = 0; // while (number <= 100) // total += number; // number += 5; Console.WriteLine(" " + total); number total while number 100 total 1050 while for

3.3.3 do while 64 do while while while do while do while( ); do while true 3-13 3-13 do while do while while do while while do while while do while do while 3-11 do while string answer = "no"; do Console.WriteLine(" "); Console.WriteLine("1.6:30-7:00 \n2.7:00-7:30 \n3.7:40-8:10 \n4.8:30-17:30 \n5.17:50-18:20 \n6.18 30-19:30 \n7.19:30-22:00 \n8.22:00 "); Console.Write(" Yes/No "); answer = Console.ReadLine(); while (answer.tolower() == "no");

Console.WriteLine(""); answer while no do 3-14 65 3-14 3.3.4 foreach foreach for foreach (var item in collection) var item collection 3-15 3-15 foreach foreach for foreach

3-12 foreach 66 Console.Write(" "); string inputcontent = Console.ReadLine(); foreach (char inp in inputcontent) Console.WriteLine(inp); 3-16 3-16 C# break goto return continue 3.4.1 break break switch while do while if break 3-13 foreach break string[] famous = "", " ", "", "" ; foreach (string fam in famous) if (fam == "") break;

Console.Write(fam + " "); famous foreach famous foreach if fam break 67 3.4.2 continue continue continue while do for foreach continue break continue break continue while do for foreach continue continue for 3-17 3-17 continue for 3-13 break continue string[] famous = "", " ", "", "" ; foreach (string fam in famous) if (fam == "")

68 continue; Console.Write(fam + " "); 3.4.3 return return return return return 3 14 1 1 2 3 5 8 13 21 public static int Fibonacci(int number) if (number == 1 number == 2) return 1; return Fibonacci(number - 1) + Fibonacci(number - 2); static void Main(string[] args) int inputnum = Fibonacci(14); Console.WriteLine(" 14 " + inputnum); Fibonacci() n int if 1 2 1 Main() Fibonacci() 14 14 377 3.4.4 goto goto

goto ; goto switch switch case default case default goto goto for try catch finally 69 3-15 Choose: Console.WriteLine(" "); Console.WriteLine("A.\tB.\tC. \t\td. \t\te."); Console.Write(":"); string answer = Console.ReadLine(); if (answer!= "C") Console.WriteLine(""); goto Choose; goto Right; Right: Console.WriteLine(" "); if C goto Choose goto Right Right 3-18 3-18

70 C# static void Main(string[] args) double result = 0; OperNum: Console.WriteLine(" "); Console.Write(""); double num1 = Convert.ToDouble(Console.ReadLine()); Console.Write(""); double num2 = Convert.ToDouble(Console.ReadLine()); Console.Write(" + - * / % "); string oper = Console.ReadLine(); switch (oper) case "+": Console.WriteLine("0 1 2", num2, num2, num1 + num2); break; case "-": Console.WriteLine("0 1 2", num2, num2, num1 - num2); break; case "*": Console.WriteLine("0 1 2", num2, num2, num1 * num2); break; case "/": if (num2 == 0) Console.WriteLine(" 0 "); goto OperNum;

Console.WriteLine("0 1 2", num2, num2, num1 / num2); break; case "%": if (num2!= 0) Console.WriteLine("0 1 2", num2, num2, num1 % num2); Console.WriteLine(" 0 "); goto OperNum; break; default: Console.WriteLine(" "); goto OperNum; break; 71 result switch case / % num2 0 0 goto OperNum 3-19 3-19 if switch

72 100 100 1 2 2 1 4 1 100 25 50 static void Main(string[] args) for (int gong = 0; gong <= 25; gong++) for (int mu = 0; mu <= 50; mu++) int small = 100 - gong - mu; if ((100-4 * gong - 2 * mu) * 2 == small) Console.WriteLine("0 1 2 ", gong, mu, small); for small if 3-20 3-20 1 C# 2 if 3 4 C# 4 for do while foreach

1 while do while A do while while B while do while C while if D do while while 2 73 string day = ""; switch (day) case "": case "": case "": Console.WriteLine(" "); case "": Console.WriteLine(" "); case "": Console.WriteLine(" "); default: Console.WriteLine(" "); Console.ReadLine(); A B C D 3 int count = 0; for (int i = 0; i < 10; i++) if (i % 2 == 0 i % 3 == 0) continue; count += i; Console.WriteLine(count);

Console.ReadLine(); 74 A 15 B 13 C 10 D 4 A break continue return goto B goto C continue D return double int string object 5 count if count int count = 100; if (count % 2 == 0) Console.WriteLine(" 2 "); if (count % 5 == 0) Console.WriteLine(" 5 "); if (count % 10 == 0) Console.WriteLine(" 10 "); Console.WriteLine(" 2 5 10 "); A 2 B 5 C 10 D 2 5 10 1 1 3-21 3-21

2 if 7 1 1 200 8.5 2 9 3 200 7.5 if 75 3 A 85 4 9*9 3-22 3-22 3.8.1 http://bbs.itzcn.com/thread-19277-1-1.html Console.WriteLine(" ");

76 int row = Convert.ToInt32(Console.ReadLine()); for (int i = 1; i <= row; i++) for (int j = 1; j <= row - i; j++) Console.Write("#"); for (int k = 1; k <= 2 * i - 1; k++) Console.Write("*"); Console.WriteLine(); 3.8.2 do while do while http://bbs.itzcn.com/thread-19278-1-1.html int i, j; for (i = 1; i <= 9; i++) j = 1; do Console.Write("\t*"); j++; Console.WriteLine(); while(j<6); Console.WriteLine(); Console.ReadLine(); 3-23 3-23 C# C# do while for while

do while do 3.8.3 for http://bbs.itzcn.com/thread-19279-1-1.html 77 for - - - - - 1/2 1+(1/2) (1+(1/2))/2 double winesurplus = 0; for (int i = 0; i < 3; i++) winesurplus = winesurplus + 1; // winesurplus = winesurplus / 2; // Console.WriteLine(wineSurplus);