Young Coders: Some Basics

Before our first session, start playing around with Java! The first step in learning how to program is to learn how to output to the console. Not only will printing show you what your program is doing, but it will also help you debug. That’s why almost everyone’s first program is to print out “Hello, World!” to the console!
1
2
3
4
5
public class HelloWorld{
   public static void main(String[] args) {
      System.out.println("Hello, World!");
   }
}


That wasn't very interesting! Let's try writing an if statement. Also known as conditional statements, if statements control which path your program executes.
1
2
3
4
5
6
7
8
9
public class LargerVal{
   public static void main(String[] args) {
      if(38*278 78*78)
          System.out.println(38*278);
      else
          System.out.println(78*78);
   }
}
Try running the program yourself. If 38*278 is larger than 78*78, whatever 38*278′s result is will be printed out. Else if 78*78 is larger than 38*278, you will see 78*78′s value in the console.
Now that you know some basics, try solving these problems: 
1) Print the biggest product out of 3*4, 2*7, and 1*10 using if statements.
2) A number is "cold" if it's less than 32. Write a program that prints "BRRR" if a number is "cold".
 Feel free to leave any questions in the comments below!

Popular posts from this blog

Space Race: a simple Rust game built on the Bevy framework

Building a Toy Language Compiler in Go

tldr: Raft + Implementation Tips