Learning Java Programming Concepts in Spring 2023

cse 121 lesson 3 n.w
1 / 9
Embed
Share

"Explore Java programming concepts including variables, operators, strings, and characters in the Spring 2023 lesson by instructor Miya Natsuhara. Get ready for quizzes, assignments, and more exciting learning activities!"

  • Java Programming
  • Variables
  • Operators
  • Strings
  • Spring 2023

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CSE 121 Lesson 3 Miya Natsuhara Spring 2023 Music: 121 23sp Lecture Vibes TAs: Jasmine Shananda Vidhi Larry Jacqueline Afifah Atharva Julia Anju Lydia Jonus Hugh Mia Archit Grace Kailye Joshua James Justin Aishah Claire Lydia Kai sli.do #cse121

  2. Announcements, Reminders C0 was due last night P0 was released on Wednesday and is due Tuesday, April 11 This will be our typical schedule for assignments! Quiz 0 scheduled for April 20 (about 2 weeks away) More details about quizzes will be released in the coming week Lesson 3 - Spring 2023 2

  3. (PCM) Variables Now that we know about different types and data, we can learn about how to store it! Declaration: Initialization: int x; x = 30; Java allows you to create variables within a program. A variable has A type A name (Potentially) a value it is storing Or all in one line: int x = 30; Lesson 3 - Spring 2023 3

  4. (PCM) Variables Notice this doesn't really make any mathematical sense! That's because, in Java, = is assignment, not equality! They re made to be manipulated, modified, re-used! int myFavoriteNumber = 7; int doubleFV = myFavoriteNumber * 2; myFavoriteNumber = myFavoriteNumber + 3; Lesson 3 - Winter 2023 4

  5. New Operators! myFavoriteNumber = myFavoriteNumber + 3; This type of pattern is so common, we have an even shorter way we can write it! myFavoriteNumber += 3; You can do the same for -=, *=, /=, and %= And there are even shorter versions for incrementing and decrementing! myFavoriteNumber++; myFavoriteNumber--; Lesson 3 - Spring 2023 5

  6. Poll in with your answer! What do a, b, and c hold after this code is executed? A.10, 30, 40 int a = 10; int b = 30; int c = a + b; c -= 10; a = b + 5; b /= 2; B.35, 15, 30 C.35, 15.5, 30 D.20, 15, 30 Lesson 3 - Spring 2023 6

  7. (PCM) Strings and chars String = sequence of characters treated as one, yet can be indexed to get individual parts Zero-based indexing g u m b a l l 0 1 2 3 4 5 6 Side note: new data type! char, represents a single character, so we use single quotes Strings are made up of chars! Lesson 3 - Winter 2023 7

  8. (PCM) String Methods Usage: <string variable>.<method>( ) Method Description Returns the length of the string. length() Returns the character at index i of the string charAt(i) Returns the index of the first occurrence of s in the string; returns - 1 if s doesn't appear in the string indexOf(s) Returns the characters in this string from i (inclusive) to j (exclusive); if j is omitted, goes until the end of the string substring(i, j) or substring(i) Returns whether or not the string contains s contains(s) Returns whether or not the string is equal to s (case-sensitive) equals(s) Returns whether or not the string is equal to s ignoring case equalsIgnoreCase(s) Returns an uppercase version of the string toUpperCase() Returns a lowercase version of the string toLowerCase() Lesson 3 - Winter 2023 8

  9. Poll in with your answer! Suppose s contains the String "bubble gum". Which option below would result in s containing "Gumball" instead? A.s.substring(7) + "ball"; B.s = s.substring(7, 9) + "ball"; C.s = s.charAt(7).toUpperCase() + "ball"; D.s = b u b b l e g u m s.substring(7, 8).toUpperCase() + s.substring(8) + "ball"; 0 1 2 3 4 5 6 7 8 9 E.s = s.substring(7, 8).toUpperCase() + s.substring(7, 10) + "ball"; Lesson 3 - Spring 2023 9

Related


More Related Content