3. Printing in Java

freepik.com

We have learned how to create variables in Java
Now we are gonna learn how to print these variables values on the screen

First of all we need a java file, java class with same name , and a main method

public class first{
public static void main(String[] args) {

}
}

After we write these, we need to add this method :
System.out.println();

Code should look like this

public class first{
public static void main(String[] args) {
System.out.println();
}
}

Inside the parentheses, we can write a number or string in double quotation marks "like this"

Example print code

public class first{
public static void main(String[] args) {
System.out.println("Hello world");
int x = 7;
System.out.println(x);
}
}

And the output should look like this :

Hello world
7

hello-java

Printing multiple variables

If you want to print multiple variables with multiple types
You should put "+" sign between the variables

Example Print

printing-java
Home Page
Previous Lesson -> Variables
Next Lesson -> Functions
First Photo from www.freepik.com, Codes are mine
Burakhan Ünver