Cleaning up comments from the non-comment branch

This commit is contained in:
2024-05-14 19:10:20 -04:00
parent c90b3a95fe
commit f402bf42b8
3 changed files with 2 additions and 120 deletions

View File

@@ -1,55 +1,17 @@
import java.util.Scanner;
/*
CS2 Demo
System.out and System.in
This demo goes over how to write and read text
from the console so that we can have some basic input and
output from our Java program
*/
public class Main {
public static void main(String[] args) {
//System.out.println is used when you want
//to put some text into the console when your program is
//running. A lot of the time, you'll see the first
//programming example your trying to learn is
//a "Hello World!" example. System.out.println
//is one of many ways that you can output text
//to the console
System.out.println("Hello World!");
System.out.println("This is console out!");
//A Scanner is used together with System.in to collect
//text, numbers, true and false values, etc. from users
//of your program. While Scanner is not the only
//way of interacting with System.in, it's one of the
//more straightforward ways
Scanner scan = new Scanner(System.in);
//Notice that we use System.out.print and System.out.println
//here, the difference is one moves the text cursor to the
//next line after writing the text you asked for (println)
//and one doesn't (print)
System.out.print("Write some text: ");
//Scanner.nextLine() can be used to capture text
//from the user. Below, we combine some already written
//text with whatever the user ends up typing in. The nice
//thing about Scanner.nextLine() is that the program
//won't move forward until the user hits Enter on the
//keyboard
System.out.println("You wrote: " + scan.nextLine());
//Some resources, like Scanner, need to be closed. This
//"frees" the resource so that it's available for another part
//of this program (or another program running on the computer)
//to access it. In this case, because we're at the end of our
//program, closing Scanner isn't really necessary, but it's
//a good practice to get into, because there are some resources
//that need to be closed before your program finishes, otherwise
//you may "break" that resource for other programs.
scan.close();
}
}