Console Printing
Today we are going to learn how to make our programs output stuff to the console. Fascinating right? However this will allow us to write programs to interact with users which will be the basis of most of the programs you will write. This will reveal a lot of the power of programming in time to come - the ability to reduce an extremely complex problem to entering a few numbers and receiving the answer for the user in fractions of a second.
The Code
To print out to the console you write the following command in Java:
System.out.print("");
Where:
System.out - outputs on a system console created by Java.
print() - a command in Java to print out whatever is between the parentheses.
"" - Quotation marks. If you want to print out words ("hello world", "Hey what's up", "Enter your name here: ") or characters ('a', 'g') to the console that aren't stored in a string variable (recall the lesson on Text Datatypes), then you must surround your message with quotation marks. That represents text in Java which is called a String and can be stored in a String variable.
System.out.print("");
Where:
System.out - outputs on a system console created by Java.
print() - a command in Java to print out whatever is between the parentheses.
"" - Quotation marks. If you want to print out words ("hello world", "Hey what's up", "Enter your name here: ") or characters ('a', 'g') to the console that aren't stored in a string variable (recall the lesson on Text Datatypes), then you must surround your message with quotation marks. That represents text in Java which is called a String and can be stored in a String variable.
The following video is provided by Edhesive.
The Process of Executing Code
FRC Programming Note: Init Versus Periodic
InitCode in Init is run the very first time your code is run for that mode (robot, teleop, autonomous, test, etc.) and it is only run once.
|
PeriodicThis code runs after init and runs repeatedly for that mode (autonomous, teleop, test, disabled , etc.) until the mode is over.
|
Your code starts at the top and works its way down the page of your code. When it reach the bottom it is done, however if it is in a periodic mode it executes the code again and again until the mode is over. It does this extremely quickly. In FRC your code typically executes every 20 miliseconds. You can time your cycle however with some work using the Timer Class from the FIRST API.
Console Printing Quiz
Answer feedback
Answer feedback
Answer feedback