In previous post we learned how to write a very simple hello world Java program. In this simple program we will explain what are some different data types in Java. We use specific data types to define variable depending upon the nature of data we want to store in variable.
public class DataTypesJava { public static void main(String[] args) { //single line comment boolean isBoolean = true; // boolean data type store either true or false int isInt = 120; // int data type is used to store integer values int mult = isInt * 2; // multiplication is basic arithmetic operation int mod = isInt % 2; // modulus operator is used to find remainder System.out.println(isBoolean); System.out.println('A'); //characters are enclosed in single quotes System.out.println("Some String Text"); // strings are enclosed in double quotes System.out.println(isInt); System.out.println(mult); System.out.println(isInt / 2); // division is simple arithmetic operation System.out.println(mod); } }
Output:
why the last output is Zero and how its came here ?
Its the output of ‘mod’ variable (modulus operator). When we divide 120 by 2 then the modulus (remainder is 0). That’s why its output is 0.