Todays Work Hw3 - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Todays Work Hw3

Description:

Today's Work (Hw3 #1) Read Note on textbook 40. Floating ... Use parseInt(String s, int radix) to get decimal value. Convert this decimal value to character ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 6
Provided by: pyun
Category:
Tags: hw3 | radix | todays | work

less

Transcript and Presenter's Notes

Title: Todays Work Hw3


1
Todays Work (Hw3 1)
  • Read Note on textbook 40
  • Floating-point numbers are stored
    approximately(Example)System.out.println( 1 -
    0.1 -0.1 - 0.1 - 0.1 - 0.1 )gt
    0.5000000000000001 (Not 0.5)System.out.println(
    1.0 - 0.9 )gt 0.09999999999999998 (Not 0.1)
  • Integer numbers are stored precisely
  • Calculation with integers yield a precise
    integer result
  • Read caution on Page 42
  • Division of two integers yields an integer in
    Java.
  • (Example)( 5/9) gt 0( 5.0 / 9 ) gt
    0.5555555555555556
  • Cast operator
  • double re
  • re ((double)5/9)

2
Todays Work ( 2)
  • Converting positive decimal integer to binary
  • (Example) See Page 11
  • Use mod () operator to get remainder
  • 9 gt 9/2 4 gt 92 1
  • 4/2 gt 2 gt 42 0
  • 2/2 gt 1 gt 22 0
  • 1001 ( 1 23 ) ( 0 22 ) ( 0 21)
    (1 20) 9
  • Use while loop and repeated division by 2
  • Use string concatenation () to prepend each new
    remainder
  • String a 001"
  • String b 1a ba gt a 1001"

3
Todays Work ( 3)
  • Reads four hexadecimal digits and displays the
    corresponding Unicode character in a JOptionPane.
  • Example
  • entering 0041 will display A
  • entering 0067 will display g
  • Use parseInt(String s, int radix)to get decimal
    value
  • Convert this decimal value to character
  • iInteger.parseInt("0041",16)
  • System.out.println((char)i)

4
Todays Work (3)
  • Check if the input is 4-digit number
  • use String.length() method
  • if (hexstring.length() 4)
  • Check if input is hexadecimal digit
  • try
  • i Integer.parseInt (hexstring, 16)
  • catch (Exception ex)
  • System.out.println( This is not
    hexadecimal value")

5
Todays Work (4)
  • Make True table like Table 2.8,2.9,2.10 (page 48,
    49)
  • --------------------------------------------------
    --
  • p1 p2 p1p2
  • --------------------------------------------------
    -
  • False false false
  • false true false
  • true false false
  • true true true
  • Use a static method
  • For (int p1int 0 p1int lt 1 p1int)
  • p1 intToBoolean(p1int)
Write a Comment
User Comments (0)
About PowerShow.com