Data%20Types - PowerPoint PPT Presentation

About This Presentation
Title:

Data%20Types

Description:

Lec2_Java. 1. Data Types. Operators. Control Flow Statements ... Bitwise operators. Lec2_Java. 5. Control Flow Statements. decision making. if-else, switch-case ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 13
Provided by: sciBrook
Category:
Tags: 20types | bitwise | data

less

Transcript and Presenter's Notes

Title: Data%20Types


1
Introduction to the Java Language
  • Data Types
  • Operators
  • Control Flow Statements
  • Arrays
  • Functions -- Static Methods
  • View Classes as modules

2
Exampe1 Hello.java
class Hello public static void main(String
args) System.out.println("Hello World!")

3
Data Types
  • byte,short,int,long
  • float,double
  • char
  • boolean
  • reference
  • array
  • object

4
Operators
  • Arithmetic operators , -, , /, , , --
  • Relational operators gt, gt, lt, lt, , !
  • Conditional operators , , !
  • Bitwise operators gtgt, ltlt, gtgtgt, , , ,

5
Control Flow Statements
  • decision making
  • if-else, switch-case
  • loop
  • for, while, do-while
  • exception
  • try-catch-finally, throw
  • miscellaneous
  • break, continue, label , return

6
Arrays
Type a new Typen
a0
a1
an-1
  • Dynamic
  • Array initialization
  • a.length

Type a ... a new Typeexpn
a new Typee1,e2,...,en A e1,e2,,en
7
Example 2 Max.java
class Max public static void main(String
args) int a new int5,6,1,2,7,9,0,10
int max max a0 for (int i1
ilta.length i) if (aigtmax) max
ai System.out.println(" max"max)

8
Example 3 PrintArray
class PrintArray public static void
main(String args) int a new
int1,2,3, 4,5,6, 7,8,9 for (int
i0 ilta.length i) for (int j0 jlt
a0.length j) System.out.print(aij"
") System.out.println()

9
Functions -- Static Methods
class Max public static void main(String
args) int a new int5,6,1,2,7,9,0,10
System.out.println(" max"max(a))
static int max(int a) int max a0
for (int i1 ilta.length i) if
(aigtmax) max ai return max

10
Functions -- Static Methods
class PrintArray public static void
main(String args) int a new
int1,2,3, 4,5,6, 7,8,9
printArray(a) static void
printArray(int a) for (int i0
ilta.length i) for (int j0 jlt
a0.length j) System.out.print(aij"
") System.out.println()

11
View Classes as Modules
class Sort public static void
selectionSort(int a) int tmp for (int
i0 ilta.length i) for (int ji1
jlta.length j) if (aigtaj) tmp
ai ai aj aj tmp
12
View Classes as Modules
public class TestSort public static void
main(String args) int a new
int5,6,1,2,7,9,0,10 Sort.selectionSort(a)
for (int i0 ilta.length i)
System.out.print(ai" ")
Write a Comment
User Comments (0)
About PowerShow.com