Download presentation
Presentation is loading. Please wait.
1
CSE 1321 - Module 1 A Programming Primer
4/5/2019 CSE 1321 Module 1
2
Ps Skeletons BEGIN MAIN END MAIN
Note: every time you BEGIN something, you must END it! Write them as pairs! 4/5/2019 CSE 1321 Module 1
3
Skeletons class MainClass { public static void main (String[] args) {
} Note: Capitalization matters! 4/5/2019 CSE 1321 Module 1
4
Ps Printing BEGIN MAIN PRINT “Hello, World!”
PRINT “Bob” + “ was” + “ here” END MAIN Ps 4/5/2019 CSE 1321 Module 1
5
Printing class MainClass { public static void main (String[] args) {
System.out.println("Hello, World!"); System.out.println("Bob"+" was"+" here"); } Note: There’s also a System.out.print() 4/5/2019 CSE 1321 Module 1
6
Declaring/Assigning Variables
BEGIN MAIN CREATE userName CREATE studentGPA userName ← “Bob” studentGPA ← 1.2 END MAIN userName “Bob” studentGPA 1.2 Ps 4/5/2019 CSE 1321 Module 1
7
Declaring/Assigning Variables
class MainClass { public static void main (String[] args) { String userName; float gpa; userName = "Bob"; gpa = 1.2f; } 4/5/2019 CSE 1321 Module 1
8
Reading Text from the User
BEGIN MAIN CREATE userInput PRINT “Please enter your name” READ userInput PRINT “Hello, ” + userInput END MAIN Ps 4/5/2019 CSE 1321 Module 1
9
Reading Text from the User
import java.util.Scanner; class MainClass { public static void main (String[] args) { String userInput; System.out.print("Please enter your name: "); Scanner sc = new Scanner (System.in); userInput = sc.nextLine(); System.out.println("Hello, "+userInput); } 4/5/2019 CSE 1321 Module 1
10
Reading Numbers from the User
BEGIN MAIN CREATE userInput PRINT “Please enter your age: ” READ userInput PRINT “You are ” + userInput + “ years old.” END MAIN Ps 4/5/2019 CSE 1321 Module 1
11
Reading Numbers from the User
import java.util.Scanner; class MainClass { public static void main (String[] args) { int age; System.out.print("Please enter your age: "); Scanner sc = new Scanner (System.in); age = sc.nextInt(); System.out.println("You are "+age+" years old."); } 4/5/2019 CSE 1321 Module 1
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.