Skip to content

Commit 8e2ff26

Browse files
authored
Create Variable
0 parents  commit 8e2ff26

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

Diff for: Variable

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
public class Variables {
2+
public static void main(String[] args) {
3+
// examples of Java variables
4+
int age = 18; // valid and good practice
5+
int AGE = 20; // valid and good practice
6+
int myAge = 22; // valid and good practice
7+
int my_age = 21; // valid and good practice
8+
int _age = 25; // valid but bad practice
9+
int $age = 32; // valid but bad practice
10+
int 1age = 19; // invalid variable
11+
int my age = 23; // invalid variable
12+
13+
byte itemQuantity = 5;
14+
byte batteryLevel = 85;
15+
short numOfSmartphones = 350;
16+
short numOfTablets = 125;
17+
int userAge = 28;
18+
int accountNumber = 123456;
19+
int x = 5;
20+
int y = 6;
21+
System.out.println(x + y);
22+
23+
int myNum = 15;
24+
myNum = 20;
25+
System.out.println(myNum);
26+
27+
int x1 = 12, y1 = 15, z1 = 17;
28+
System.out.println(x1 + y1 + z1);
29+
30+
int x2, y2, z2;
31+
x2 = y2 = z2 = 35;
32+
System.out.println(x2 + y2 + z2);
33+
34+
int totalStudents = 30; // Number of students in the course
35+
System.out.println("Total number of students: " + totalStudents);
36+
37+
long creditCardNumber = 1234_5678_9012_3456L;
38+
long worldPopulation = 7_900_000_000L;
39+
long population = 1393409038L; // Population of India (in billions)
40+
System.out.println("Population of India: " + population);
41+
42+
double accountBalance = 5000.50;
43+
double personHeight = 1.75;
44+
float temperatureCelsius = 37.5f;
45+
double averageScore = 85.7; // Average score of the student
46+
System.out.println("Student's average score: " + averageScore);
47+
48+
float itemPrice = 19.99f; // Price of the item
49+
float totalPrice = itemPrice * 1.1f; // Total price with tax (10%)
50+
System.out.println("Total price with tax: " + totalPrice);
51+
52+
boolean isLoggedIn = true; // Status of user login
53+
boolean isActiveAccount = true;
54+
boolean isSubscribed = true;
55+
56+
char initialLetter = 'J';
57+
char grade = 'A'; // Student's grade
58+
System.out.println("Student's grade: " + grade);
59+
60+
String userEmail = "[email protected]";
61+
String studentName = "John Doe"; // Student's name
62+
System.out.println("Student's name: " + studentName);
63+
String myString = "Java Programming Language";
64+
65+
double TAX_RATE = 0.08; // Constant tax rate of 8%
66+
double price = 100.0;
67+
double tax = price * TAX_RATE;
68+
double total = price + tax;
69+
System.out.println("Total price with tax: " + total);
70+
71+
// approximate light speed in miles per second
72+
int lightSpeed = 186000;
73+
long days = 1000;
74+
long seconds;
75+
long distance;
76+
seconds = days * 24 * 60 * 60; // convert to seconds
77+
distance = lightSpeed * seconds; // compute distance
78+
System.out.println("In " + days);
79+
System.out.println(" days light will travel about ");
80+
System.out.println(distance + " miles");
81+
82+
}
83+
}

0 commit comments

Comments
 (0)