j1-1_strings
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| j1-1_strings [2024/11/28 00:54] – appledog | j1-1_strings [2024/12/05 06:40] (current) – appledog | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| Scroll down to the second option, the " | Scroll down to the second option, the " | ||
| - | == Entering The Program | + | == Variables |
| + | First explain the basic structure of a Java program and demonstrate basic integer variables. Then show how to print them out. | ||
| + | |||
| + | < | ||
| + | public class Main { | ||
| + | public static void main(String[] args) { | ||
| + | int a = 5; | ||
| + | int b = 3; | ||
| + | int c = a + b; | ||
| + | |||
| + | System.out.println(c); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Don't discuss anything else yet, just play around with integer math a bit, and show what a function is: | ||
| + | |||
| + | < | ||
| + | public class Main { | ||
| + | public static void main(String[] args) { | ||
| + | int a = 5; | ||
| + | int b = 3; | ||
| + | int c = a + b; | ||
| + | |||
| + | System.out.println(c); | ||
| + | |||
| + | int d = mul(a, b); | ||
| + | |||
| + | System.out.println(d); | ||
| + | } | ||
| + | |||
| + | public static int mul(int a, int b) { | ||
| + | int c = a * b; | ||
| + | |||
| + | return c; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | == Strings | ||
| Start a new project called "J1-1 Strings" | Start a new project called "J1-1 Strings" | ||
| === Main.java | === Main.java | ||
| < | < | ||
| + | import java.util.Scanner; | ||
| + | |||
| public class Main { | public class Main { | ||
| public static void main(String[] args) { | public static void main(String[] args) { | ||
| Line 54: | Line 95: | ||
| Teacher may discuss the answers here. | Teacher may discuss the answers here. | ||
| - | == The Code | + | == Don't Read This Section |
| Here's an explanation of what each line of the program does. We will look at it like a computer looks at it. First, here's the basic starter program: | Here's an explanation of what each line of the program does. We will look at it like a computer looks at it. First, here's the basic starter program: | ||
| Line 92: | Line 133: | ||
| This means the function doesn' | This means the function doesn' | ||
| - | == The Code | + | == The Code (Read This Part!) |
| === System.out.println(" | === System.out.println(" | ||
| This kind of code just prints a message out. | This kind of code just prints a message out. | ||
j1-1_strings.1732755260.txt.gz · Last modified: 2024/11/28 00:54 by appledog
