Slides0112 - COP 3330 Slides 1/12 Topics Strings Basic I/O...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Slides 1/12 COP 3330
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics Strings Basic I/O Control Flow Arrays
Background image of page 2
String Basics Java has a String class ( Difference from C ) String concatenation can be performed with the ‘+’ operator String literals are enclosed in double quotes - Example: “This is a string literal”
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
String Basics String comparison is done using the equals method and compareTo method If x and y are strings, then x.equals(y) returns true if and only if they are the same string x.compareTo(y) returns negative if x is lexicographically less than y, 0 if they’re the same, positive if x is greater than y
Background image of page 4
Basic I/O- To Screen Output to screen is handled through System.out out is a static field in the System class System.out is an object of type PrintStream
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Basic I/O- To Screen Useful methods for use with System.out: - print- Takes in a parameter of any type and outputs it to the screen - println- Behaves just like print, except it also advances output to the next line afterwards - printf- Behaves almost identically to C’s printf function ( New to Java 5.0 )
Background image of page 6
Basic I/O- To Screen Example- The following are all roughly equivalent (assuming that x is an int) - System.out.print(“Value is “ + x + “\n”); - System.out.println(“Value is “ + x); - System.out.printf(“Value is %d\n”, x); - System.out.printf(“Value is “ + x + “\n”);
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/09/2010 for the course CS COP 3330 taught by Professor Douglass during the Spring '09 term at University of Central Florida.

Page1 / 27

Slides0112 - COP 3330 Slides 1/12 Topics Strings Basic I/O...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online