Announcements - PowerPoint PPT Presentation

About This Presentation
Title:

Announcements

Description:

Celsius to Fahrenheit. class CToF{ public static void main(String arg[]){ double C = 40; ... 32; System.out.println(C 'Celsius is same as ' F ' Fahrenheit' ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 10
Provided by: iit1
Category:

less

Transcript and Presenter's Notes

Title: Announcements


1
Announcements
  • B7 tutorial today 1100-1200 in CS103
  • In CSE department
  • Ask at entry desk for direction to CS103

2
Unary and binary operators
  • Operators acting on a single variable or an
    expression are called unary operators
  • Example logical NOT, unary plus, unary minus
  • boolean x true
  • boolean y !x // unary logical NOT
  • int z 23
  • int w z // unary plus
  • int k -z // unary minus or negation
  • int j -z-20 // what is j -43 or -3?
  • int r -(z-20) // what is r?

3
Unary and binary operators
  • Operators acting on two variables or expressions
    are called binary operators
  • Example add (), subtract (-), multiply (),
  • Example of boolean operators (unary and binary)
  • boolean x true
  • boolean y !x x
  • boolean z !(y x)
  • boolean w !y !x
  • boolean k !(y x)
  • boolean p !y !x

4
Examples
  • Instructor Mainak Chaudhuri
  • mainakc_at_cse.iitk.ac.in

5
Printing characters
  • class printcharacter
  • public static void main(String arg)
  • char gradeA
  • System.out.println(grade) // prints A
  • System.out.println((int)grade) // prints
    65
  • System.out.println(gradeB) // prints
    131
  • System.out.println(grade1) // prints 66
  • System.out.println((char)(grade1)) //
    prints B
  • Notice the type cast
  • Notice the automatic type conversion

6
Printing characters
  • class printcharacter
  • public static void main(String arg)
  • char gradeA
  • System.out.println(grade)// prints A
  • System.out.println(grade) // prints B
  • Post-increment

7
Printing characters
  • class printcharacter
  • public static void main(String arg)
  • char gradeA
  • System.out.println(grade)// prints B
  • System.out.println(grade) // prints B
  • Pre-increment

8
More type cast
  • class castExample
  • public static void main(String arg)
  • double xMath.PI // Call to Math class
  • double y-Math.PI
  • System.out.println(Value of PI is x)
  • System.out.println((int)x) // prints 3
  • System.out.println((int)y) // prints -3

9
Celsius to Fahrenheit
  • class CToF
  • public static void main(String arg)
  • double C 40
  • double F
  • F (C/5.0)9.0 32
  • System.out.println(C Celsius is same as
    F Fahrenheit)
Write a Comment
User Comments (0)
About PowerShow.com