AP Comp Sci stuff
by EpicSkills32, Sep 10, 2014, 6:36 PM
![$\ [\text{Blog Post 123}] $](http://latex.artofproblemsolving.com/1/9/4/1944542382d0022d3d057f9008ccf4fbd880a215.png)
In case you didn't know, AP Computer Science is done in Java. All of the code I'll be doing will be Java.
You can actually download all the programs necessary for free. For my course, I'm just using this Java Development Kit (JDK) and DrJava. When I run the DrJava program, it opens up a window where I can input code and run it.
For every lesson in my class, I download a template with which I add or change code. For example, here's the lesson 1 template:
Java template 1
/* * Lesson 1 - Unit 1 - Output in Java * This program uses a Scanner to ask you (the user) for their name and favorite number. */ import java.io.*; import static java.lang.System.*; import java.util.Scanner; class t01_lesson1_template{ public static void main (String str[]) throws IOException { System.out.println ("Welcome to AP Comp Sci"); System.out.println ("Programming in Java"); System.out.println("MOOC"); System.out.println ("\"I do not fear computers. I fear the lack of them.\" \n Isaac Asimov"); } }
(Actually it wasn't like that. I added the last few lines myself)
Explanation of the code
So the top 15ish lines aren't really important right now. All we need to know and work with right now are the last few lines. You'll notice the same thing at the beginning of those lines:
One of the most important commands in java is the System.out.print command. Basically what it does is it displays text on the screen. If we run the program above, we get this:
Welcome to AP Comp Sci
Programming in Java
MOOC
"I do not fear computers. I fear the lack of them."
Isaac Asimov
Whatever is inside the quotation marks is displayed, or "printed."
The "ln" after the System.out.print simply makes the next line of code displayed on another line.
Another important thing to remember in code is the semicolon. After each line of code, you put a semicolon to mark the end of the command or whatever.
System.out.println ("whatever")
One of the most important commands in java is the System.out.print command. Basically what it does is it displays text on the screen. If we run the program above, we get this:
Welcome to AP Comp Sci
Programming in Java
MOOC
"I do not fear computers. I fear the lack of them."
Isaac Asimov
Whatever is inside the quotation marks is displayed, or "printed."
The "ln" after the System.out.print simply makes the next line of code displayed on another line.
Another important thing to remember in code is the semicolon. After each line of code, you put a semicolon to mark the end of the command or whatever.
Example
Let's say you want the computer to display "Hello. I am epic." (without the quotation marks)
Using the template that has some necessary setup stuff:
For the output, you would use the System.out.print command:
Using the template that has some necessary setup stuff:
import java.io.*; import static java.lang.System.*; import java.util.Scanner; class t01_lesson1_template{ public static void main (String str[]) throws IOException {
For the output, you would use the System.out.print command:
import java.io.*; import static java.lang.System.*; import java.util.Scanner; class t01_lesson1_template{ public static void main (String str[]) throws IOException { System.out.print("Hello. I am epic."); } }