-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariables.java
More file actions
25 lines (24 loc) · 1.12 KB
/
Variables.java
File metadata and controls
25 lines (24 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package BasicJavaPrograms;
public class Variables {
public static void main(String[] args) {
// Variety Of DataTypes
// --- Primitive Datatypes ----
byte by = 100; // Byte variable
short sh = 32767; // Short variable
char ch = 'A'; // Char variable
boolean bl = true; // Boolean variable
long lg = 123456789L; // Long variable/ String variable
int age = 20; // Integer variable
int a = 10; // Integer variable
float b = 3.14f; // Double variable
double sum= a + b; // Adding int and double, result is double
// --- Non-Primitive Datatypes ----
String name = "Atharv"; // String variable
// Other Datatypes include Arrays, Classes, Objects, Interfaces, etc.
System.out.println("Sum of a and b: " + sum);
System.out.println("Byte : " + by + "\n" + "Short : " + sh + "\n");
System.out.println("Char : " + ch + "\n" + "Boolean : " + bl + "\n");
System.out.println("Long : " + lg + "\n" + "Integer : " + age + "\n");
System.out.println("User : " + name + "\n" + "Age : " + age);
}
}