Programming se7
This presentation is the property of its rightful owner.
Sponsored Links
1 / 279

Programming (SE7) PowerPoint PPT Presentation


  • 116 Views
  • Uploaded on
  • Presentation posted in: General

Programming (SE7). 環境工程系 丁文輝 [email protected] 環境工程系電腦課程 ( 規画案 ). 計算機概論 (BCC) 計算機程式 (Programming) 計算機圖學 (CG) 資料庫管理系統 (DBMS) 數値分析 (NA) 地理資訊系統 (GIS) 環工電腦應用. 逢甲大學水利工程學系工學士 中央大學 ( 教育部委訓 ) 大專資訊師資班 成功大學環境工程學系工學碩士 成功大學環境工程學系博士候選人. 自己紹介 - 澄原日先 ( すみはら ひさき ). 台中市坤財營造廠工地主任

Download Presentation

Programming (SE7)

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Programming se7

Programming (SE7)

[email protected]


Programming se7

()

  • (BCC)

  • (Programming)

  • (CG)

  • (DBMS)

  • (NA)

  • (GIS)

Java programming


Programming se7

()

-()

Java programming


Programming se7

FORTRAN, BASIC, PASCAL, JAVA

8086/8088, 80286

PE, dBASE+, Lotus 123, Office, ACAD, SAS/SPSS, Sigma Plot, GIS

,

()

Java programming


Programming se7

  • JAVA2 (JDK7)

    () (2012)

  • Java SE7

    (2011)

  • Java

    (), (2006)

  • JAVA SE6

    (2009)

Java programming


Programming se7

Java

  • (),

    • http://kgclass.jp/text/java

  • (JAVA Note),

    • http://irw.ncut.edu.tw/peterju/java.html

  • (),

    • http://elearning.ksu.edu.tw

Java programming


Programming se7

  • 4

Java programming


Programming se7

  • 40%)20%)40%)

  • (101_2)java1002626

(A 20%, B 31%)

Java programming


Programming se7

  • 10:00-11:30

  • 10:00-11:30

  • 10:00-11:30

    • 34F(D3402)

      • tingmail.ksu.edu.tw

Java programming


Java se7 2013

Introduction

Datatype

Input/Output

Assignment

Selection

Iteration

Array

Method

(Java SE7, 2013)

Java programming


Programming se7

Console

Assignment

Expression

Divisor

If / If-else

Switch-case

For loop

While loop

Random

Bubble sort

Method

Recursive

Java programming


Programming se7

a=b+c;

a*ba>b

for,if

Java programming


Programming se7

Delphi

C++Builder

FORTRAN

PL/1

COBOL

ALGOL

ALGOL68

PASCAL

Ada

Object PASCAL

BASIC

C

C++

Lisp

Java

Prolog

Smalltalk

Java programming


Programming se7

FORTRAN

BASIC

Pascal

Java programming

Java (2011)


Programming se7

Java programming


Programming se7

Java programming


Programming se7

Java programming


Programming se7

Java programming


Programming se7

(1)

  • SmallTalk

  • C++

    • C

Java programming


Programming se7

(2)

  • Java

    • C

    • Unix, Windows(Write Once, Run Anywhere)

Java programming


Programming se7

(3)

  • Ruby

  • Visual Basic, Visual C++

    • Microsoft

  • C#

    • MicrosoftJava like

Java programming


Programming se7

  • (object)

    • (property)

    • (method)

  • (class)

    • (variable)

    • (instance)

Java programming


Programming se7

(1)

  • (encapsulation)

    • () ()

  • (inheritance)

    • (Parent Class)

Java programming


Programming se7

(2)

  • (polymophism)

      • (Overloading):

      • (Overriding):

Java programming


Java version history

Java version history

JDK 1.0 (January 23, 1996)

JDK 1.1 (February 19, 1997)

J2SE 1.2 (December 8, 1998)

J2SE 1.3 (May 8, 2000)

J2SE 1.4 (February 6, 2002)

J2SE 5.0 (September 30, 2004)

Java SE 6 (December 11, 2006)

Java SE 7 (July 28, 2011)

Java programming


Programming se7

Java

  • Java(1.2) JDK(Java Deve-lopment Kit) Java 2 SDK(Software Development Kit)

    • J2EE(Enterprise Edition)

    • J2SE(Standard Edition)

    • J2ME(Micro Edition)

Java programming


Java platforms

Java Platforms

Java Card for smartcards.

Java Platform, Micro Edition (Java ME).

Java Platform, Standard Edition (Java SE).

Java Platform, Enterprise Edition (Java EE).

Java programming


Java platform edition

Java Platform Edition

Java programming


Programming se7

JAVA

Java programming


Development environments

Development Environments

  • Sun Java Development Kit (JDK)

  • Sun NetBeans

  • IBM Eclipse, GNU Eclipse

  • Borland JBuilder

  • MetroWerks CodeWarrior

  • BlueJ

  • jGRASP

Java programming


Interpretation vs compilation

Interpretation vs. Compilation

C++ Source (*.c)

Java Source (*.java)

C++ Compiler

Java Compiler

Byte-code (*.class)

Java Virtual Machine

Client Platform (hardware/operating system)

Client Platform (hardware/operating system)

Java programming


Jdk java development kit

JDK(Java Development Kit)

Java programming


Jdk java development kit1

JDK(Java Development Kit)

Java programming


Jdk java development kit2

JDK(Java Development Kit)

  • javac(.exe)

    • Java, .java.class

  • java(.exe)

    • JVM, Java ApplicationBytecode(.class)

Java programming


J ava virtual machine

Java Virtual Machine

JavaVM

JavaVM

javac

JavaVM

Java programming


Java virtual machine

Java Virtual Machine

Java programming


Java virtual machine1

Java Virtual Machine

Java programming


Garbage collection 1

Garbage Collection (1)

  • Garbage Collection

  • []:

    int[ ] a = new int[100];

    int[ ] b = new int[200];

    a = b;

Java programming


Garbage collection 2

Garbage Collection (2)

  • nullGarbage Collection

  • []:

    int[ ] c = new int[300];

    c = null;

Java programming


Garbage collection 3

Garbage Collection (3)

  • Garbage Collection ;

Java programming


Ide integrated development environment

IDE (Integrated Development Environment)

  • NetBeans (Sun)

  • JBuilder (Borland)

  • Eclipse (IBM)

Java programming


Programming se7

Java

Windows

Mac

Linux

JVMWindows

JVMMac

JVM Linux

Java

Java programming


Java 1

Java (1)

(Simple)C/C++

(Object-oriented)OOPPIE()

Java programming


Java 2

Java (2)

(Network-Savvy)API

(Interpreted)bytecodeJVMJIT

(Robust)

Java programming


Java 3

Java (3)

(Secure) (Garbage Collection)JVM (Exception)

(Architecture Neutral)

Java programming


Java 4

Java (4)

(Portable) Write once, run any-whereJVM

(High Performance)HotSpot, JIT

(Multithreaded)Java

Java programming


Java 5

Java (5)

  • (Dynamic)Java

  • (Unicode)

Java programming


Data type

(Data type)

  • (primitive data type)

  • (structured data type)

  • (abstract data type)

Java programming


Java 11

Java(1)

JavaC/C++

JavacharUnicode, ,

Java

1.2.

Java programming


Java 21

Java(2)

  • (wrapper class) java.lang

  • (byte, short, int, long)10, 816

  • (float, double)double

Java programming


Java 31

Java(3)

boolean()

(operators)+= , -=, *= , /=()

Java programming


Data type1

data type

Java programming


Data type2

(Data type)

  • (primitive type)

    • (byte, short, int, long)

    • (float, double)

    • (boolean)

    • (char)

  • (non-primitive type)

Java programming


Primitive types

primitive types

Java programming


Primitive type

(primitive type)

Java programming


Programming se7

Java programming


Java 12

Java (1)

  • boolean :

    • truefalse

  • byte:

    • -128127

  • short

    • -3276832767

  • int

    • 32

      -21474836482147483647

Java programming


Java 22

Java (2)

  • long

    • -92233720368547758089223372036854775807

  • floatIEEE754

  • doubleIEEE754

  • char

    • 16UCS-2ASCII

Java programming


Java 32

Java (3)

  • ; 32 bits (-231 ~ 231-1)int, long

  • double

Java programming


Default values

Default Values

Java programming


Java fi nal

Javafinal

Java programming


Primitive data types

Primitive Data Types

Java programming


Primitive data type wrapper class

Primitive Data Type Wrapper class

Java programming


Programming se7

  • long, Ll

  • float, Ff

  • , :

    • ()

Java programming


String 1

String (1)

String.valueOf(boolean b)

String.valueOf(char c)

String.valueOf(char[] data)

String.valueOf(char[] data, int offset, int count)

Java programming


String 2

String (2)

String.valueOf(double d)

String.valueOf(float f)

String.valueOf(int i)

String.valueOf(long l)

String.valueOf(Object obj)

Java programming


String

String

Byte.parseByte(String s)

Double.parseDouble(String s)

Float.parseFloat(String s)

Integer.parseInt(String s)

Long.parseLong(String s)

Java programming


Programming se7

  • //

  • a = b + c; /* */

  • /*

    *

    */

  • /**

    * javadoc

    */

Java programming


Commenting

commenting

// This is an example of a single line comment using two slashes

/* This is an example of a multiple line comment using the slash and asterisk. This type of comment can be used to hold a lot of information or deactivate code but it is very important to remember to close the comment. */

/**

* This is an example of a Javadoc comment;

* Javadoc can compile documentation from this text.

*/

Java programming


Programming se7

Java

Java programming


Java lang math

java.lang.Math

Java programming


Programming se7

Math.();

class MathExample {

public static void main(String[] args) {

System.out.println("-5" + Math.abs(-5));

System.out.println("3.0" + Math.sqrt(3.0));

System.out.println

("2" +2*2*Math.PI);

System.out.println

("sin60" + Math.sin(60.0*Math.PI / 180.0));

}

}

Java programming


I o byte

I/O(byte)

Java programming


I o char

I/O(char)

Java programming


Bufferedreader

BufferedReader

import java.io.*;

public class {

public static void main(String args[]) throws IOException

{

BufferedReader buf;

String str1;

buf= new

BufferedReader(new InputStreamReader(System.in));

str1=buf.readLine();

............

}

}

Java programming


Programming se7

(1)

import java.io.*;

class Sample1 {

public static void main (String args[])throws IOException

{

System.out.println();

BufferedReader br =

new BufferedReader(new InputStreamReader(System. in));

String str = br.readLine();

System.out.println( + str);

}

}

Java programming


Programming se7

(2)

import java.io.*;

class Sample2 {

public static void main(String args[]) throws IOException

{

System.out.println();

BufferedReader br =

new BuffereReader(new InputStreamReader(System.in));

String str = br.readLine();

int num = Integer.parseInt(str);

System.out.println( = + num);

}

}

Java programming


Console

Console

import java.io.Console;

public class {

public static void main(String args[])

{

Console console=System.console();

String str1;

str1=console.readLine()

int i = Interger.parseInt(str1);

............

}

}

Java programming


Java util scanner

java.util.Scanner

  • Scanner

    • BufferedReader

    • Integer.parselnt()

Java programming


Scanner

Scanner

  • import java.util.Scanner;

    • Scanner sc = new Scanner(System.in);

    • Scanner sc =

      new Scanner(new FileStream("filename.txt"));

Java programming


Scanner methods

Scanner Methods

Java programming


Numeric and string methods

Numeric and String Methods

Java programming


Boolean methods

Boolean Methods

Java programming


Scanner 1

Scanner(1)

import java.util.Scanner;

public class {

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

System.out.println();

int i = sc.nextInt();

}

}

Java programming


Scanner 2

Scanner(2)

import java.util.Scanner;

public class Input {

public static void main(String[] args) {

Scanner cin = new Scanner(System.in);

//

float a = cin.nextFloat(), b = cin.nextFloat();

//

System.out.println(a + b); //a+b

String c = cin.next(); //

System.out.println(c); //c

}

}

Java programming


Escape sequence character

(Escape sequence character)

Java programming


Java util formatter

java.util.Formatter

Java programming


Format

format

%[argument_index$] [flags] [width] [.precision] conversion

Java programming


Common formatting codes

Common Formatting Codes

Java programming


Conversion 1

Conversion (1)

Java programming


Conversion 2

Conversion (2)

Java programming


Programming se7

Java programming


Programming se7

flag

Java programming


Printf 1

printf (1)

  • Example 1:

    • System.out.printf(%5.3f, Math.PI)

      53

      3.142

      ()

Java programming


Printf 2

printf (2)

  • Example 2: argument_index

    • System.out.printf(%s and %s, You, Me)

      You and Me

    • System.out.printf(%2$s and %2$s, You, Me)

      Me and Me

Java programming


Programming se7

Console

Assignment

Expression

Divisor

If / If-else

Switch-case

For loop

While loop

Random

Bubble sort

Method

Recursive

Java programming


J ava virtual machine1

Java Virtual Machine

JavaVM

JavaVM

javac

JavaVM

Java programming


Programming se7

Java programming


Programming se7

java

Eclipse, JCreator LE

Jbuilder, IntelliJ IDEA, Visual Cafe, Workshop, Forte for Java

Crimson, ConText, NotePad

UltraEdit, EditPlus

Java programming


Jdk java development kit3

JDK(Java Development Kit)

  • javac(.exe)

    • Java, .java.class

  • java(.exe)

    • JVM, Java ApplicationBytecode(.class)

Java programming


Programming se7

Java programming


Programming se7

Java

1)

  • ()

  • .javaTest.java

    2)

  • javac javac Test.java

    3)

  • java Testjava Test

Java programming


Java 10 1 by david reilly

Java10 (1)By David Reilly

  • 10Accessing non-static member variables from static methods (such as main)

  • 9 Mistyping the name of a method when overriding

  • 8 Comparison assignment ( = rather than == )

  • 7 Comparing two objects ( == instead of .equals)

Java programming


Java 10 2 by david reilly

Java10 (2)By David Reilly

  • 6 Confusion over passing by value, and passing by reference

  • 5 Writing blank exception handlers

  • 4 Forgetting that Java is zero-indexed

  • 3 Preventing concurrent access to shared variables by threads

  • 2 Capitalization errors

  • 1 Null pointers

Java programming


Programming se7

  • MS Word (filename = A4010N099_09),

  • , , mail

    ([email protected])

(, , _, )

Java programming


Programming se7

Java programming


Programming se7

Java

  • (Application)

    • Java

  • (X-let)

    • (Applet)Java appletHTML

    • (Servlet)

Java programming


Java application

Java Application

Java programming


Application

Application()

/* package */package exam.test;import java.awt.Button; import java.util.*;

public class HelloWorld {public static void main( String[] args ) {System.out.println( Hello World ); tmp obj = new tmp(); obj.i = 6; System.out.println( obj.i );}}class tmp{int i = 5; }

Java programming


Programming se7

Java

Class Name

Variable NameMethod Name

,2

4

,javadoc

Java programming


Java 13

Java(1)

80

if

()

Java programming


Java 23

Java(2)

class

method

("_")

Java programming


Java 33

Java(3)

    • Code Conventions for the Java Program-ming Language

      http://www.oracle.com/technetwork/java/

      codeconvtoc-136057.html

Java programming


System out println print

System.out.println() /.print()

  • System.out.println()

    • \r\nConsole()

  • System.out.print()

    • Console()

  • (+)

Java programming


System out printf

System.out.printf()

Java programming


System out printf1

System.out.printf() -()

Java programming


Programming se7

java

  • D:\>md myjava

  • D:\>cd myjava

  • D:\myjava>

  • ,filename: Ex01.javaD:\myjava

  • D:\myjava>javac Ex01.java //

  • D:\myjava>java Ex01 //

Java programming


Hello java

Hello.java

public class Hello

{

public static void main(String args[ ])

{

System.out.println("Hello");

}

}

Java programming


Ex01 java

/*

1: Hello, java!

: Ex01.java

A, 4010N901,

*/

package myjava.ex01;

import java.lang.*;

import java.io.Console;

Ex01: java

Java programming


Programming se7

()

public class Ex01

{

public static void main (String args[])

{

System.out.println(Hello, java!);

}

}

Java programming


K r kernighan ritchie

K&R(Kernighan & Ritchie)

if () {

for ( ; ; ) {

while () {

}

}

}

Java programming


Java 14

java(1)

/*......*///..............., javadoc /**........*/

.java

class, public

Java programming


Java 24

java(2)

  • class, .class

  • Java

Java programming


Java 15

Java (1)

Unicode(Keywords)

Class Name Variable Name Method Name

Java programming


Java 25

Java (2)

  • ,(camelcase) (Hungarian Notation)

Java programming


Java programming language keywords

Java Programming Language Keywords

Java programming


Class

class

class

class , public

Java programming


Package 1

package(1)

  • package

  • package

  • JavaclassespackagesJDK src.zip

    • ()java.awt.Button.javapackage package java.awt

Java programming


Package 2

package(2)

  • packageclass package packageclass

    • () java.io.InputStreamjava.ioInputStream

  • classpath + package =

Java programming


Import 1

import(1)

Java import C include java import VM

java.io FileReader import java.io.FileReader

Java programming


Import 2

import(2)

  • java.io , import java.io.*

  • import , import; import java.io.File File,FileReader

Java programming


Import 3

import(3)

  • java.lang import java.lang;

Java programming


Import 4

import(4)

  • javaAPIclasspackage java.util java.sql Date class, import package import class

Java programming


Java 16

java(1)

java.lang

java.io

java.util

javax.swing

Java programming


Java 26

java(2)

  • java.awt

    • JDK1.1GUI

  • java.awt.event

    • GUI

  • java.awt.image

    • GUIImage

Java programming


Class interface enum

class, interface, enum

class

class , public

Java programming


Programming se7

(1)

  • imoport java.io.console;

  • Console = System.console();

  • String str = .readLine();

[]: String()

Java programming


Programming se7

(2)

  • imoport java.util.Scanner;

  • Scanner = new Scanner (System.in);

  • String str = .next();

[]:

Java programming


Scanner1

Scanner

Java programming


Programming se7

(3)

  • import java.io.*

  • main(String args[]) throws IOException

  • BufferedReader = new BufferedReader (new InputStreamReader (System.in));

  • String str = .readLine();

[]: String()

Java programming


Programming se7

Java programming


Programming se7

1:

  • Hello, java SE7 !

Java programming


Programming se7

1:

Java programming


Assignment

(assignment)

  • = ;

Java programming


Programming se7

  • 1[=1], 2[=2];

Java programming


Arithmetic

(Arithmetic)

Java programming


Programming se7

(/)

  • doubledouble

  • doubleintdouble

  • intint

Java programming


Logic

(Logic)

Java programming


Programming se7

(Bit)

Java programming


Programming se7

Java programming


Operator precedence 1 2

Operator Precedence (1/2)

Java programming


Operator precedence 2 2

Operator Precedence (2/2)

Java programming


Operator

(Operator)

Java programming


Java printf method

Java printf( ) method

System.out.printf(format-string [, arg1, arg2, ]);

Java programming


Format string

Format String

  • % [flags] [width] [.precision] conversion-character

Java programming


Flags

Flags

  • - : left-justify ( default is to right-justify )

  • + : output a plus ( + ) or minus ( - ) sign for a numerical value

  • 0 : forces numerical values to be zero-padded ( default is blank padding )

  • , : comma grouping separator (for numbers > 1000)

  • : space will display a minus sign if the number is negative or a space if it is positive

Java programming


Conversion characters

Conversion-Characters

  • d : decimal integer [byte, short, int, long]

  • f : floating-point number [float, double]

  • c : character. Capital C will uppercase the letter

  • s : String. Capital S will uppercase all the letters in the string

  • h : hashcode. A hashcode is like an address. This is useful for printing a reference

  • n : newline. Platform specific newline character- use %n instead of \n for greater compatibility

Java programming


Printf format specifiers

printf format specifiers

Java programming


Special printf characters

special printf characters

Java programming


Programming se7

2: (1)

  • Celsiustemperature ()

  • Fahrenheit temperature ()

  • = + 32

Java programming


Programming se7

2: (1)

Java programming


Programming se7

()

http://www2.health.ne.jp/theme/index.html

Java programming


Programming se7

()

http://www2.health.ne.jp/theme/index.html

BMI25

B:

A:

BMI25

85cm

90cm

Pickwick

CT

100cm2

A:

B:

Java programming


Programming se7

http://www2.health.ne.jp/theme/index.html

Java programming


Programming se7

(18)

19992 ""

Java programming


Programming se7

http://www2.health.ne.jp/theme/index.html

Java programming


Programming se7

http://www2.health.ne.jp/theme/index.html

    • 11

    • 31

(jogging)

(training)

Java programming


Programming se7

Java programming

98.5.14. A8


Programming se7

Java programming

98.5.14. A8


Programming se7

Java programming


Programming se7

    • BMI 18.5-249080

Java programming


Programming se7

    • 2drinks/day,15360120~15030~401

    • 14090 mmHg

Java programming


Programming se7

BMIkgm2 ; kg22m2

http://www.uemura-clinic.com/dmlecture/bmi.htm

Java programming


Programming se7

Java programming

(2000)


Programming se7

3: (2)

  • BMI [()] [(m)]2

  • () 22m2

  • BMIBody Mass Index

Java programming


Programming se7

3: (2)

Java programming


Programming se7

4:

  • 1 = 12

  • 1 = 2.54

Java programming


Programming se7

Math

Java programming


Programming se7

Math

Java programming


Java lang math round x

java.lang.Math round(x)

Java programming


Programming se7

4:

Java programming


Programming se7

(1)

    • if (expression) statement;

    • if (expression) statement_true; else statement_false;

Java programming


Programming se7

switch (expression) { case value_1: [statement_1;] [break;]

case value_2: [statement_2;] [break;]

...

default: statement;

[break;]

}

(2)

Java programming


Programming se7

  • if () ;

  • if ()

    ;

  • if () {

    ;

    }

Java programming


Programming se7

if ()

A;

else

B;

if () {

A;

}

else {

B;

}

Java programming


Programming se7

  • = () ? Y : N;

  • []

    • int n1 = -20, n2 = 5;

      String compare;

      compare = (n1 >= n2) ? : ;

Java programming


Programming se7

if () {

if (1) {

A;

}

else {

B;

}

}

else {

if (2) {

C;

}

else {

D;

}

}

Java programming


5 if else

5: if else

  • If

    • If...

    • If...Else ...

    • (34.0)

      + [-]

    • ()

Java programming


Programming se7

(1). ( - )

(2).

Java programming


Programming se7

[]61930

Java programming


5 if else1

5: if else

Java programming


6 switch

6: switch

  • Select Case (VB6 )

    • Case is <= 5

    • Case 6, 7, 8

    • Case 9 To 14

    • Case is >= 15

    • Case Else

Java programming


Programming se7

switch () {

case 1:

1;

break;

case 2:

2;

break;

:

case n:

n;

break;

default:

default;

[break;]

}

: char, byte, short, intenum

:

Java programming


6 switch1

6: switch

  • ()(100)

    • 0 - 4915%

    • 50 - 7910%

    • 80 - 1005%

Java programming


6 switch2

6: switch

Java programming


Programming se7

(1)

: for

for( init_Statement ; condition ; incre_statement ) statement

Java programming


Programming se7

(2)

  • : while

    • while( expression ) statement

Java programming


Programming se7

(3)

  • : do while

    • do statement while( expression ) ;

Java programming


Programming se7

(1)

  • label

    • breakcontinue,(multi-level loop)

  • break

    • for, while, do while,switch

Java programming


Programming se7

(2)

  • continue

    • for, while, do while,

  • return

    • , ,

Java programming


For loop

(for loop)

  • for (; ; ) ;

  • for (; ; ) {

    ;

    }

Java programming


While loop

<>

while () {

;

}

<>

do {

;

} while ();

(while loop)

Java programming


Programming se7

  • sum = 1 + 2 + 3 + + 100

  • sum = 2 + 4 + 6 + + 100

  • sum = 1 + 1/2 + 1/3 + + 1/20

  • sum = 1 - 1/2 + 1/3 1/20

Java programming


Programming se7

    • 1400

Java programming


Programming se7

    • tan 1 /4 tan-1(1) /4

    • tan-1(1) tan-1(1) = 1 1/3 + 1/5 - 1/7 + 1/9 +/- 4

Java programming


7 for

7: for

Java programming


8 while

8: while

  • 1,0003

Java programming


8 while1

8: while

Java programming


8 1 while

8-1: while

Java programming


Randomize statement and the rnd function

Randomize Statement and the Rnd Function

  • The Randomize statement initializes Visual Basics random-number generator.

  • The Rnd function generates random decimal numbers within the 0 to 1 range, including 0 but not including 1.

Java programming


Rnd function

Rnd Function

  • To generate random decimal numbers in a range other than 0 to 1:

    (upperbound - lowerbound + 1) * Rnd + lowerbound

  • To generate random integers:

    Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

Java programming


Programming se7

(VB6)

  • Rnd

    • Int(( - + 1) * Rnd + )

  • Randomize Timer

Java programming


Math random

- Math.random()

  • import java.lang.Math;

  • Math.random()

    • 0.0 - 1.0()(double)

  • :

    • (int) (Math.random() * ( - + 1) + )

Java programming


Programming se7

Math

random110

public class Example {

public static void main(String[] args) {

int randomNumber = (int) (Math.random() * 10 + 1);

System.out.println(randomNumber);

}

}

Java programming


Programming se7

()

  • Random

  • import java.util.Random;

    Random r = new Random();

    r.nextInt(n)//0 - (n-1)

    r.nextDouble()

    //0.0 1.0()

Java programming


Programming se7

  • private int randomInRange(int min, int max)

    {

    return min + random.nextInt(max min + 1);

    }

  • int lotto;

    lotto = randomInRange(1, 49);

Java programming


Programming se7

= 4

Java programming


Programming se7

= ((/)) / 2

= /

Java programming


Programming se7

= (11/4) / (11)

= /

if (x*x + y*y <= 1)

hit = hit + 1;

y

1

*

(x,y)

x

0

1

Java programming


Monte carlo method

Monte Carlo method

Monte Carlo method applied to approximating the value of .

After placing 30000 random points, the estimate for is within 0.07% of the actual value.

Java programming


Programming se7

9:

Java programming


Array

(Array)

Java programming


Array1

(Array)

  • (class)new

  • 2

    • [ ];

      • : int[] arr1, int[ ][ ][ ] arr3;

    • [ ];

      • : int arr1[ ];

Java programming


Declaring a reference to refer to an array

Declaring a Reference to Refer to an Array

  • type (reference)name

    type[ ] name;

  • []

    • int[ ] intArray;

    • float[ ] floatArray;

Java programming


Creating an array

Creating an Array

  • Java new

  • new elementType[arrayLength];

  • []

    • int[ ] intArr;

    • intArr = new int[100];

    • double[ ] doubleArr = new double[200];

Java programming


Array initializers

Array Initializers

  • { }

    • int[ ] anArray = {0,10,20,30,40};

    • //Create and initialize an array called anArray

    • //The length of anArray is 5

Java programming


Accessing an array element

Accessing an Array Element

  • [ ](index)

  • []

    • intArray[3] = 10;

    • float val = floatArray[3];

  • arrayReference.length

Java programming


Sorting searching an array

Sorting/Searching an Array

  • bubble sort

  • binary search on a sorted array

Java programming


Multiple subscripted arrays

Multiple-Subscripted Arrays

  • Java xy

    • int[ ][ ] a;

    • a = new int[x][y];

  • Array Initializers

    • int[ ][ ] b = { { 1, 2}, { 3, 4, 5}};

Java programming


Programming se7

  • 20021, (), 142, 6;

  • 20041, , 149, 6(6/49);

Java programming


Programming se7

Java programming


Programming se7

(6/49)

  • 01 - 496

Java programming


Programming se7

Java programming


Programming se7

Java programming

, EB631, p.6-36


Java2

(Java2)

class BBKMath {

void GenRnd( int[] x, int min, int max, int rnd_no) {

int tot_no, rem_no, t_no;

int i, j;

tot_no = max - min + 1;

int[] t = new int[tot_no];

for(i = 0; i < tot_no; i++) {

t[i] = min + i;

}

rem_no = tot_no;

for( i = 0; i < rnd_no; i++) {

t_no = (int)Math.floor(Math.random() * rem_no);

x[i] = t[t_no];

for(j = t_no; j < (rem_no - 1); j++) {

t[j] = t[j+1];

}

rem_no--;

}

}

}

Java programming

, EB631, p.6-37


Java21

(Java2)

for(int j=1;j<=i;j++) { //

int[] lotto= new int[49]; //

for (int k=0;k<49;k++) // 149

lotto[k]=k+1;

int count=0; //

do {

int guess = (int)(Math.random()*49);

if(lotto[guess]==0) // 0,

continue; // , ,

else {

System.out.print(lotto[guess]+\t");

lotto[guess]=0; // 0,

count++;

}

} while (count<6); // 6

}

Java programming

, FS720, p.17-32~33


Java22

(Java2)

import java.util.*;

public class ListLotto {

public static void main(String args[]) {

System.out.println("Java/ArrayList ");

ArrayList num = new ArrayList();

for (int i=1;i<50;i++)

num.add(new Integer(i)); //

Collections.shuffle(num); //

System.out.println(num.subList(1,7));

} // 6

}

Java programming

, FS720, p.17-60~61


Vb2008

(VB2008)

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _

System.EventArgs) Handles Button1.Click

Dim guess, A(5) As Integer

Randomize()

For index As Integer = 0 To 5

While A(index) = 0

guess = CInt(Int(Rnd() * 59) + 1)

If Array.IndexOf(A, guess) = -1 Then

A(index) = guess

End If

End While

Next

TextBox1.Text = A(0)

TextBox2.Text = A(1)

TextBox3.Text = A(2)

TextBox4.Text = A(3)

TextBox5.Text = A(4)

TextBox6.Text = A(5)

End Sub

End Class

Java programming

, HB0902, p.11-28


Vb6 0

(VB6.0)

Dim A(6) as Integer

Dim i, j, k, y as Integer

Dim temp, check as Integer

Randomize Timer

i = 0

While i <= 6

check = 0

A(i) = Int(49*Rnd() + 1)

For y = 0 to i 1

If A(i) = A(y) Then

check = -1

End if

Next y

If check = 0 Then

i = i + 1

End if

Wend

Java programming


With vb net

with VB.NET

Function GenerateArray(ByVal size As Integer) _ As Integer()

'Dim arr(size - 1) As IntegerDim i As IntegerFor i = 0 To size - 1arr(i) = iNext i

Java programming

blog.craft-works.jp/uru/id/vb1


Programming se7

'Dim r As Random = New Random()Dim tmp As IntegerFor i = 0 To size - 1Dim src As Integer = r.Next(i, size)tmp = arr(src)arr(src) = arr(i)arr(i) = tmpNext iReturn arr

End Function

Java programming


Programming se7

(1)

public class Ran{

public static void main(String[] args){

int ran = (int)(Math.random()*10);

System.out.println(ran);

}

}

Mathrandom()

Java programming


Programming se7

(2)

import java.util.Random;

public class Ran{

public static void main(String[] args){

Random rnd = new Random();

int ran = rnd.nextInt(10);

System.out.println(ran);

}

}

Random nextInt

Java programming


Programming se7

import java.util.Random;public class Test{public static void main(String args[]){Random random = new Random(); int number = 0;;int array[] = new int[6];boolean b;for(int i=0; i<6; i++){b = true;while(b) {b = false;number = random.nextInt(49)+1;for(int j=0; j<array.length; j++) {if(array[j] == number) {b = true;}}}array[i] = number;System.out.printf("array[%d]=%d\n",i,number);}}}

Java programming


Programming se7

()

  • int[] data = {10, 4, 55, 20, 15, 12};

    for (int i = 0; i < data.length - 1; i++){

    for (int j = i + 1; j < data.length; j++){

    if (data[i] >data[j]){

    int tmp = data[i];

    data[i] = data[j];

    data[j] = tmp;

    }

    }

    }

Java programming


Sorting

(sorting)

  • (bubble sort)

  • (selection sort)

  • (insertion sort)

  • (Shell sort)

Java programming


Sorting1

(sorting)

  • (quick sort)

  • (merge sort)

  • (heap sort)

  • (radix sort)

Java programming


Bubble sort method

Bubble sort method

source[i + 1] = exchange;

} // if end

} //for end

} //for end

for (short i = 0;

i < source.length; i++) {

System.out.print(source[i] + " ");

}

} //main method end

} //class end

public class BubbleSort {

public static void main(String args[]) {

short source[] = {

540, 94, 458, 47, 64};

short exchange = 0;

for (short pass = 1;

pass < source.length; pass++) {

for (short i = 0; i < source.length - 1;

i++) {

if (source[i] > source[i + 1]) {

exchange = source[i];

source[i] = source[i + 1];

Java programming


Sorting array in java

Sorting Array in Java

import java.util.Arrays;

public class HowToSortAnArray {

public static void main(String[] args) {

//Array of Integers

int[] myIntArray = new int[]{20,100,69,4};

//SORTS ARRAY FROM SMALLEST TO LARGEST INT

Arrays.sort(myIntArray);

//for loop to print Array values to console

for (int a = 0; a < myIntArray.length; a++) {

System.out.println(myIntArray[a]);

}

}

}

Java programming


Programming se7

10:

Java programming


Programming se7

*

**

***

****

*****

11: (1)

*

**

***

**

*

***

**

*

**

***

Java programming


Programming se7

*

***

*****

*******

*********

11: (2)

*****

***

*

***

*****

*

***

*****

***

*

Java programming


Programming se7

1

12

123

1234

12345

123

12

1

12

123

11: (3)

1

12

123

12

1

Java programming


Programming se7

1

121

12321

1234321

123454321

1

121

12321

121

1

11: (4)

32123

212

1

212

32123

Java programming


Programming se7

11: (_1)

Java programming


Programming se7

11: (_2)

Java programming


Method

(method)

  • [public | private | protected] static [ | void] ([]) [throws ]

    {

    ;

    [return ;]

    }

Java programming


Programming se7

java

  • :

    [].([]);

  • :

    = [].([]);

Java programming


Programming se7

[] [] (<>)

{

}

Java programming


Programming se7

()

{

return ;

}

Java programming


Programming se7

java

  • (call by value)

  • (call by reference)

    []All parameters to methods in Java are

    pass-by-value.

Java programming


Defining methods

Defining methods ()

public double calculateAnswer(double

wingSpan, int numberOfEngines,

double length, double grossTons)

{

//do the calculation here

}

Java programming


Method declaration

method declaration

All parameters to methods in Java arepass-by-value.

Modifierssuch as public, private, and others you will learn about later.

The return typethe data type of the value returned by the method, or void if the method does not return a value.

Java programming


Method definition 1

method definition (1)

class MyClass {

...

public ReturnType methodName(Type1 param1,

Type2 param2 ) throws ExceptionName {

ReturnType retType;

...

return retType;

}

...

}

Java programming


Method definition 2

method definition (2)

private void methodName(

String param1, String param2 )

{

...

return;

}

Java programming


Create a simple java method

Create a simple Java method

public class Hi { public static void main(String[] args) {sayHi(); System.out.println(The second Hi!!); } public static void sayHi() { System.out.println(The first Hi!); }}

Java programming


Programming se7

2:

  • Function

  • BMI bmi(height, weight)

    • BMI [()] [(m)]2

  • std_weight(height)

    • 22m2

Java programming


Programming se7

2:

Java programming


Method1

method

modifier returnValueType

methodName(list of parameters)

{

// Method body;

}

Java programming


Recursive method

Recursive method

Method that invokes itself.

The arguments passed to the recursion take us closer to the solution with each call.

Java programming


Recursive algorithms

recursive algorithms

if (the stopping case is reached){solve it}else{reduce the problem using recursion}

Java programming


Recursive method1

Recursive method ()

public class RecursiveFactorial{ public static void main( String [] args ) { // compute factorial of 7 and output it System.out.println( Factorial ( 7 ) is + factorial( 7 ) ); } public static int factorial( int n ) {if ( n <= 0 ) // base casereturn 1;else// general casereturn ( n * factorial ( n - 1 ) ); }}

Java programming


Int n 1 2 3 n

, (int n)1+2+3+ ... +n

public class Example {

public static void main(String[] argv) {

System.out.println(sum(100));

}

public static int sum(int n) {

int total = 0;

for (int i = 1; i <= n; i++)

total += i;

return total;

}

}

Java programming


Recursion 1 2 3 n

(recursion)1+2+3+...+n

public class Example {

public static void main(String[] argv) {

System.out.println(sum(100));

}

public static int sum(int n) {

if (n <= 1)

return 1;

else

return (n + sum(n - 1));

}

}

Java programming


Searching

(searching)

  • (sequential search)

  • (binary search)

  • (interpolation search)

  • (Fibonacci search)

Java programming


Recursive binary search

Recursive Binary Search

public static int search (int[] a, int first, int size, int target) { int middle;

if (size <= 0) return -1; else { middle = first + size/2; if (target == a[middle]) return middle; else if (target < a[middle]) // the target is less than a[middle], so search before the middle return search(a, first, size/2, target); else // the target must be greater than a[middle], so search after the middle return search(a, middle+1, (size-1)/2, target); } }

Java programming


Programming se7

3:

Java programming


Programming se7

  • [email protected]

Java programming


Programming se7

Java

  • [email protected]

Java programming


  • Login