What are Variables(Integer, Float, Boolean, String)

 



Integer

The integer is a whole number and has a certain limit. Code representation is as follows.
public class Main {
	
	public static void main(String[] args) {
	//      (Type) (variable name) = (variable value);
		
		int number1  = 100;
		int number25 = 2500;
	//      System.out.println(); a function prints values ​​enclosed in parentheses to the console. 
		System.out.println(number1);
		System.out.println(number25);
	//      Operations are performed with the +, -, *, / signs.
		int plus = number1 + number25;
		System.out.println(plus);
		int minus = number1 - number25;
		System.out.println(minus);
		int times = number1 * number25;
		System.out.println(times);
		int divide = number1 / number25;
		System.out.println(divide);	    
	}
}


 Float

The float is a fractional number and has a certain limit. Code representation is as follows.
public class Main {
	
	public static void main(String[] args) {
	//      (Type) (variable name) = (variable value);
	//	For floats, the last character must be f.	
		float number1  = 100.15f;
		float number25 = 2500.65f;
	//      System.out.println(); a function prints values ​​enclosed in parentheses to the console. 
System.out.println(number1); System.out.println(number25); //     Operations are performed with the +, -, *, / signs. float plus = number1 + number25; System.out.println(plus); float minus = number1 - number25; System.out.println(minus); float times = number1 * number25; System.out.println(times); float divide = number1 / number25; System.out.println(divide); } }


Boolean

The boolean takes true or false values. Code representation is as follows.
public class Main {
	
	public static void main(String[] args) {
	//      (Type) (variable name) = (variable value);
	//	A very important variable for codes because it is used a lot in if structures.	
		boolean b1 = true;
		boolean b2 = false;
		System.out.println(b1);
		System.out.println(b2);
		System.out.println(b1 + " " + b2);
	}
}


String

The string is an object created by combining characters. Code representation is as follows.
public class Main {
	
	public static void main(String[] args) {
	//  (Type) (variable name) = (variable value);
		
	//  String values ​​are written between quotation marks.
		String x = "Hello Blogs";
		String y = "Hello World!";

	//  System.out.println(); a function prints values ​​enclosed in parentheses to the console.
		System.out.println(x);
		System.out.println(y);

	//  You can concatenate strings with the + sign.
    		System.out.println(x + y);

	//  You can enter as many values ​​as you want.
		System.out.println(x + " You can write as much as you want. " + y);  

	//	Returns string lengths.	
		System.out.println(x.length() + "---" + y.length());		    
	}
}

Good Bye Everyone


Image resource: https://protocoderspoint.com/wp-content/uploads/2019/10/vairable-in-java-with-example-min.jpg

1 Comments