1 / 6

CPSC 233 Tutorial

CPSC 233 Tutorial. Xin Liu 2010/01/19. Basic stuffs. Variable Declare variables before using Build-in types: byte, short int , long, float, double, char, boolean , String eg . int x ; int x = 8; Constants final int SIZE = 100; Output

vinny
Télécharger la présentation

CPSC 233 Tutorial

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPSC 233 Tutorial Xin Liu 2010/01/19

  2. Basic stuffs • Variable • Declare variables before using • Build-in types: byte, short int, long, float, double, char, boolean, String • eg. intx; intx = 8; • Constants • final int SIZE = 100; • Output • System.out.print(<string or variable name one> + <string or variable name two>..); • System.out.println(<string or variable name one> + <string or variable name two>..); • Escape sequence: \t, \r, \n, \”, \\ • Input • import java.util.Scanner; • Scanner in = new Scanner (System.in); • intx = in .nextInt (); • Mostly commonly used methods • nextInt(), nextLong(), nextFloat(), nextDouble(), nextLine()

  3. Basic structures • Conditional • if, if else, nested if • switch case default • Iteration • for, while, do while

  4. Make program run • Source code/Java program  [compiler]byte-code / object program  [interpreter] machine code • Step 1: Code • Use any text editor • Eclipse is a famous Integrated Development Environment (IDE) program • Step 2: Compile • javacexample.javaexample.class • Step 3: Run • java example

  5. A hello world program • A very simple example public class HelloWorld{ public static void main(String[] args) { System.out.println("Hello world."); } }

  6. A sorting program • Algorithm: • ☐☐☐☐☐☐☐☐ • do it in n – 1 pass for n numbers • for the i pass, make the ith number the smallest among the numbers [i … n]

More Related