csci 144 introduction to
play

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


  1. 1 CSCI 144 - Introduction to Computer Science Instructor: John Goettsche Computer Science Department Pacific Lutheran University Spring 2018

  2. Strings

  3. Strings name String name; ? name = “ Fred Flintstone ” ; “ Fred Flintstone ” “ Jenn Lawrence ” name = “ Barney Rubble ” ; “ Barney Rubble ” Strings are immutable

  4. String methods String name = “ Barney ” ; name System.out.println(name.toUpperCase()); System.out.println(name.toLowerCase()); “ Barney ” System.out.println( “ length = “ + name.length()); 012345 System.out.println( “ first = “ + name.charAt(0)); System.out.println( “ last = “ + name.charAt(5)); System.out.println( “ last = “ + name.charAt(6)); BARNEY barney length = 6 first = B last = y Exception in thread “ main ” java.lang.StringIndexOutOfBoundsException

  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());

  6. Pair Practice Download and complete StringPractice.java

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend