CSCI 144 - Introduction to Computer Science Instructor: John - - PowerPoint PPT Presentation

csci 144 introduction to
SMART_READER_LITE
LIVE PREVIEW

CSCI 144 - Introduction to Computer Science Instructor: John - - PowerPoint PPT Presentation

1 CSCI 144 - Introduction to Computer Science Instructor: John Goettsche Computer Science Department Pacific Lutheran University Spring 2018 Strings Strings name String name; ? name = Fred Flintstone ; Fred Flintstone


slide-1
SLIDE 1

CSCI 144 - Introduction to Computer Science

Instructor: John Goettsche Computer Science Department Pacific Lutheran University Spring 2018

1

slide-2
SLIDE 2

Strings

slide-3
SLIDE 3

Strings

String name; name ? name = “Fred Flintstone”;

“Jenn Lawrence”

Strings are immutable

“Fred Flintstone”

name = “Barney Rubble”;

“Barney Rubble”

slide-4
SLIDE 4

String methods

String name = “Barney”;

name

“Barney”

System.out.println(“length = “ + name.length()); length = 6 System.out.println(name.toUpperCase()); System.out.println(name.toLowerCase()); BARNEY barney

012345

System.out.println(“first = “ + name.charAt(0)); System.out.println(“last = “ + name.charAt(5)); first = B last = y System.out.println(“last = “ + name.charAt(6)); Exception in thread “main” java.lang.StringIndexOutOfBoundsException

slide-5
SLIDE 5

String Practice – What’s the output?

String greeting = “Hello World!”; System.out.println(greeting.toUpperCase()); System.out.println(greeting.length()); System.out.println(greeting.charAt(9)); System.out.println(greeting.charAt(greeting.length());

slide-6
SLIDE 6

Download and complete StringPractice.java

Pair Practice