top of page
Search

Java: Basic printing and variables

  • Writer: Elon譯閬 Tsay蔡
    Elon譯閬 Tsay蔡
  • Nov 28, 2024
  • 2 min read

Updated: Mar 17

Java is a very nice programming language that is medium difficulty and pretty good speed, and this guide will guide you through it! Explore Java now with this post!


System.out.println is something computer programmers use to output something to the "Dashboard", and you can use it in this format:

System.out.println("Sigma brain rot");

and this will be the output:

Sigma brain rot

I'm using slant for the output. This is not the only way to use System.out.println, but we will get to that later.

These will cause errors:

System.out.println("Stop yapping")

System.out.println(Stop yapping);

These errors are caused by violating these important rules:

1: print statements need semicolons.

2: you need double quotes unless you are outputing variables, which we will learn later.

Comments

Comments are very simple. do this for a single line comment: //

and do this for a multi-line one: /* to start it and */ to close it. Single lines will close at the end of the line of code.


Comments will not affect code. They are only for coders to see.

this is a comment:

// Sigma Rizz

But this is not:

Sigma rizz//

Important: class and main method

P.S all Java codes need to Start with this until later topics:

Public class(name of file){

public static void main(String [] (Your choice here){

//code

}

}



Variables

In java, variables are used to store values inside something. In the real world, If I had three apples, I could store it in a variable: Lets call it NumApples.

and in Java, I could set it like this:

int NumApples = 3;

Now, we can output it using System.out.println:

System.println(NumApples);

and the output will be:

3

and we don't need double quotes!

If we put double quotes, it would print:

NumApples

BTW, int means "Integer".

here are some other types:

char = Character. It can only store one character, like G,B,v,N,d,and r. You need to put single quotes around the character, like 'e' or 't'

String = phrase. It can store phrases, like "Stop Yapping" and "The mariners are going to win tonite's game".

Strings can also store numbers, like "3", but you can't change the value with the special operators i'm talking about next!

Double is just a way of storing decimals and very big numbers.

You can modify number variables with +=, -=, *=, /=, and %=.

if I used NumApples and did NumApples += 3, NumApples would by 6,

because 3+3=6.

-=, *=, %=,and /= work the same way.

That will be it!

BTW, / = division and %= is remainder when divided by, or "Moddulo."

This'll be it for now! Catch you all later!





 
 
 

Recent Posts

See All
The mathmatics Behind Gambling

Gambling is a game enjoyed by adults around the globe, and you may be tempted to try it. Don't. The house, or the host of the game, e.g....

 
 
 
Ordinals: The roof of finite numbers

Ordinals, the topic of our discussion, are immense. Get ready as we explore the limitless potential of ordinals! We'll begin by examining...

 
 
 
The Biggest Number

This topic has intrigued mathmeticians for centuries. What’s the biggest number? Well, technically there is no biggest number, cuz u just...

 
 
 

Comments


bottom of page