User Tools

Site Tools


j1-1_strings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
j1-1_strings [2024/11/28 00:54] appledogj1-1_strings [2024/12/05 06:40] (current) appledog
Line 10: Line 10:
 Scroll down to the second option, the "Community Edition", which is free. Scroll down to the second option, the "Community Edition", which is free.
  
-== 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. 
 + 
 +<Code:Java> 
 +public class Main { 
 +    public static void main(String[] args) { 
 +        int a = 5; 
 +        int b = 3; 
 +        int c = a + b; 
 + 
 +        System.out.println(c); 
 +    } 
 +
 +</Code> 
 + 
 +Don't discuss anything else yet, just play around with integer math a bit, and show what a function is: 
 + 
 +<Code:Java> 
 +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; 
 +    } 
 +
 +</Code> 
 + 
 +== Strings
 Start a new project called "J1-1 Strings". Then type the following code into the Main.java file: Start a new project called "J1-1 Strings". Then type the following code into the Main.java file:
  
 === Main.java === Main.java
 <Code:Java|Main.java> <Code: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't return anything. Actually this surprises me, since it seems a main function should return an error code. But no, in Java there is no return. Sounds ominous. Try changing the void to an int and returning a 5. It doesn't work. This means the function doesn't return anything. Actually this surprises me, since it seems a main function should return an error code. But no, in Java there is no return. Sounds ominous. Try changing the void to an int and returning a 5. It doesn't work.
  
-== The Code+== The Code (Read This Part!)
 === System.out.println("Hello!") === System.out.println("Hello!")
 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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki